SpringBoot中,自定义的controller,服务启动后,扫描不到自定义的controller,三种可能原因总结如下:
1、自定义controller类的位置和启动器不在一个目录下,或者启动器不在controller类的根目录下
2、启动器类注解
①如果使用@Controller和@EnableAutoConfiguration 注解还应该再加上一个注解:@ComponentScan 就可以了。@Controller和@EnableAutoConfiguration没有扫描注解的功能,而@ComponentScan是springboot专门用来扫描@Component, @Service, @Repository, @Controller等注解的注解
②@SpringBootApplication注解等价于@Configuration, @EnableAutoConfiguration and @ComponentScan
3、在配置文件中配置扫描包<context:component-scan base-package="com.test" />