spring boot 自定义controller路由找不到,原因是启动类和自定义的Controller包不在同一级目录下。

官方建议application.java放的位置:
spring boot 自定义controller不能扫描到的问题

解决的办法:
1、把自建的controller类放到启动类同一级目录下(不建议这样做)。

2、把启动类@RestController @EnableAutoConfiguration注解改成@SpringBootApplication。

3、启动类@RestController @EnableAutoConfiguration注解再加上@ComponentScan注解。

使用springboot扫描的两种注解配置方式:
1、@Controller
  @EnableAutoConfiguration
  @ComponentScan

2、@SpringBootApplication

总结:@SpringBootApplication注解等价于以默认属性使用@Configuration,@EnableAutoConfiguration和@ComponentScan

相关文章:

  • 2022-12-23
  • 2021-08-04
  • 2022-02-11
  • 2021-06-05
  • 2022-12-23
  • 2021-09-15
  • 2022-12-23
猜你喜欢
  • 2021-12-19
  • 2021-08-10
  • 2021-06-14
  • 2021-06-17
  • 2021-10-06
相关资源
相似解决方案