如何解決springboot啟動的時候required a bean of type 'XXX' not be問題
springboot啟動的時候required a bean of type ‘XXX’ not be
Deion:Field mapper in com.kaigejava.kgblog,service.impl.UserServiceImpl required a bean of type ‘com.kaigejava.kgblog.dao.UserDao’ that could not be found.Action:Consider defining a bean of type ‘com.kaigejava.kgblog.dao.UserDao’ in your configuration.
SpringBoot啟動失敗,告訴我Bean配置失?。?/p>
解決方案一
添加@Mapper注解,
@Mapper
public interface UserDao(){
int insert(UserDomain record);
List<UserDomain> selectUsers();
}重新啟動,啟動正常。
特別注意:
添加了@Mapper注解之后這個接口在編譯時會生成相應(yīng)的實(shí)現(xiàn)類
需要注意的是:這個接口中不可以定義同名的方法,因?yàn)闀上嗤膇d
也就是說這個接口是不支持重載的 。
說明:如果使用@Mapper這個注解的話,每個dao都需要添加麻煩。
解決方案二
使用@MapperScan:
@SpringBootApplication
@MapperScan("com.example.demo.model.dao")
public class GctimeApplication {
public static void main(String[] args) {
SpringApplication.run(GctimeApplication.class, args);
}
}方案二使用@MapperScan就可以很好的解決該問題的。
總結(jié)
以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Intellij IDEA使用restclient測試的教程圖解
這篇文章主要介紹了Intellij IDEA使用restclient測試的教程圖解,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-01-01
Springboot 整合 Java DL4J 實(shí)現(xiàn)時尚穿搭推薦系統(tǒng)(實(shí)例代碼)
本文介紹了如何使用SpringBoot和JavaDeeplearning4j框架搭建一個時尚穿搭推薦系統(tǒng),文章詳細(xì)闡述了系統(tǒng)的技術(shù)架構(gòu)、數(shù)據(jù)集格式、Maven依賴配置、模型訓(xùn)練和預(yù)測代碼實(shí)現(xiàn),以及單元測試和預(yù)期輸出結(jié)果2024-10-10
SpringBoot之自定義Filter獲取請求參數(shù)與響應(yīng)結(jié)果案例詳解
這篇文章主要介紹了SpringBoot之自定義Filter獲取請求參數(shù)與響應(yīng)結(jié)果案例詳解,本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-09-09
使用Spring的ApplicationEvent實(shí)現(xiàn)本地事件驅(qū)動的實(shí)現(xiàn)方法
本文介紹了如何使用Spring的ApplicationEvent實(shí)現(xiàn)本地事件驅(qū)動,通過自定義事件和監(jiān)聽器,實(shí)現(xiàn)模塊之間的松耦合,提升代碼的可維護(hù)性和擴(kuò)展性。同時還介紹了異步事件和事件傳遞的相關(guān)知識2023-04-04

