PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

SpringBoot扫描不到Controller怎么解决

WBOY
WBOY 转载
2023-05-14 08:10:17 3770浏览

SpringBoot小白创建项目,扫描不到Controller一系列问题

1.

SpringBoot扫描不到Controller怎么解决

2.

SpringBoot扫描不到Controller怎么解决

3.

SpringBoot扫描不到Controller怎么解决

4.

SpringBoot扫描不到Controller怎么解决

5.

SpringBoot扫描不到Controller怎么解决

6.还有一种办法是在启动服务类的入门,添加@ComponentScan(basePackages={“xxx.xxx.xx”,“xxx.xxx.xx”})里面的是包的全限定名,可以为多个

SpringBoot 自定义controller无法扫描到

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

官方建议application.java放的位置: 其余Bean与application.java放在同一个包路径下,但是不建议这么做。

SpringBoot扫描不到Controller怎么解决

解决的办法:

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

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

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

使用springboot扫描的两种注解配置方式:

1、第一种

@Controller 
@EnableAutoConfiguration 
@ComponentScan

2、第二种

@SpringBootApplication      
@ComponentScan

以上就是SpringBoot扫描不到Controller怎么解决的详细内容,更多请关注php中文网其它相关文章!

声明:本文转载于:亿速云,如有侵犯,请联系admin@php.cn删除