首頁  >  文章  >  Java  >  SpringBoot掃描不到Controller怎麼解決

SpringBoot掃描不到Controller怎麼解決

WBOY
WBOY轉載
2023-05-14 08:10:176301瀏覽

SpringBoot小白建立項目,掃描不到Controller一系列問題

1.

SpringBoot掃描不到Controller怎麼解決

#2.

SpringBoot掃描不到Controller怎麼解決

#3.

SpringBoot掃描不到Controller怎麼解決

4.

SpringBoot掃描不到Controller怎麼解決

#5.

SpringBoot掃描不到Controller怎麼解決

SpringBoot掃描不到Controller怎麼解決6.還有一個方法是在啟動服務類別的入門,加入@ComponentScan(basePackages={“xxx.xxx.xx”,“xxx.xxx.xx”})裡面的是包的全限定名,可以為多個

SpringBoot 自訂controller無法掃描到

SpringBoot 自訂controller路由找不到,原因是啟動類別和自訂的Controller包不在同一層目錄下。

官方建議application.java放的位置: 其餘Bean與application.java放在同一個套件路徑下,但不建議這麼做。

解決的方法:

1、把自建的controller類別放到啟動類別同一層級目錄下(不建議這樣做)。

2、把啟動類別@RestController @EnableAutoConfiguration註解改成@SpringBootApplication。

3、啟動類別@RestController @EnableAutoConfiguration註解再加上@ComponentScan註解。 #########使用springboot掃描的兩種註解配置方式:##########1、第一種###
@Controller 
@EnableAutoConfiguration 
@ComponentScan
###2、第二種###
@SpringBootApplication      
@ComponentScan

以上是SpringBoot掃描不到Controller怎麼解決的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:yisu.com。如有侵權,請聯絡admin@php.cn刪除