解决的办法:
1、把自建的controller类放到启动类同一级目录下(不建议这样做)。
2、把启动类@RestController @EnableAutoConfiguration注解改成@SpringBootApplication。
3、启动类@RestController @EnableAutoConfiguration注解再加上@ComponentScan注解。
使用springboot扫描的两种注解配置方式:
1、@Controller
@EnableAutoConfiguration
@ComponentScan
2、@SpringBootApplication
总结:@SpringBootApplication注解等价于以默认属性使用@Configuration,@EnableAutoConfiguration和@ComponentScan
引用https://blog.youkuaiyun.com/Fandly168/article/details/73302281
发现问题还是没解决,后方法上加入@ResponseBody后成功返回数据,但是数据是json类型
因为我这个项目只是提供服务,所以我的已经解决,但是考虑到以后可能要返回页面,就找了下原因
/**
* pom.xml文件
*/
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
查看pom是否少了这些包,就可以解决不加@ResponseBody也能访问的问题