首頁  >  文章  >  Java  >  springboot啟動報錯bean找不到怎麼解決

springboot啟動報錯bean找不到怎麼解決

王林
王林轉載
2023-05-24 16:28:064465瀏覽

    springboot啟動錯誤bean找不到的原因解決

    一.普通的dao,service對應的實例bean不存在

    錯誤範例:

    1.Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.

    Reason: Failed to determine a suitable driver class。

    解決方案:

    1.確實不存在,加進去就好了

    2.類別存在,但是spring沒有掃描到,注意啟動類別所在位置,springboot預設掃描的是啟動類別所在目錄下的子包和類,如下圖1.2所示。另外可以使用@componentScan這個註解指定掃描的套件:範例@componentScan({“xxx.xx”,“xxx.xx”})

    springboot啟動報錯bean找不到怎麼解決

    二.由於bean的載入順序與設定檔的關係

    1.請參考以下部落格文章

    https://www.yisu.com/article/222850.htm

    https:// www.yisu.com/article/190698.htm

    https://www.yisu.com/article/229466.htm

    補充:Springboot啟動錯誤之類文件具有錯誤的版本61.0, 應為52.0

    啟動Springboot專案時候報錯

    java: 無法存取org.springframework.boot.SpringApplication
    錯誤的類別檔案: /D:/Maven/apache-maven -3.6.3/repository/org/springframework/boot/spring-boot/3.0.0/spring-boot-3.0.0.jar!/org/springframework/boot/SpringApplication.class
    類別檔案具有錯誤的版本61.0, 應為52.0
    請刪除該檔案或確保該檔案位於正確的類別路徑子目錄中。

    springboot啟動報錯bean找不到怎麼解決

    原因

    SpringBoot使用了3.0或3.0以上,因為Spring官方發佈從Spring6以及SprinBoot3.0開始最低支援JDK17,所以只需將SpringBoot版本降低為3.0以下即可。

    springboot啟動報錯bean找不到怎麼解決

    將SpringBoot版本降低為3.0以下 版本隨意,刷新Maven重啟即可

    springboot啟動報錯bean找不到怎麼解決

    以上是springboot啟動報錯bean找不到怎麼解決的詳細內容。更多資訊請關注PHP中文網其他相關文章!

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