Consider defining a bean of type 'XX.XX.XX.XX.mapper.XXMapper' in your configuration.


 

今天構建一個springboot 項目,采用mybatis+mysql 然后就出現了這種錯誤....浪費我半天時間

 1 Description:
 2 
 3 Field loginLogMapper in com.guoll.modules.sysmanage.service.PassagewayService required a bean of type 'com.guoll.modules.sysmanage.mapper.LoginLogMapper' that could not be found.
 4 
 5 The injection point has the following annotations:
 6 - @org.springframework.beans.factory.annotation.Autowired(required=true)
 7 
 8 
 9 Action:
10 
11 Consider defining a bean of type 'com.guoll.modules.sysmanage.mapper.LoginLogMapper' in your configuration.
12 
13 
14 Process finished with exit code 0

錯誤原因:是由於springboot 掃描不到 mapper

 

解決方案:

 第一種:在mapper包下類配置@Mapper 注解

第二種:在springboot 啟動類上配置包掃描@ComponentScan()

 

第三種:在springboot 啟動類上配置Mapper掃描@MapperScan(注意:必須將路徑指定到 xxx.xxx.xxx.mapper 包為止,否則依舊掃描不到) 多個mapper路徑 可以以 @MapperScan({mapper1路徑,mapper2路徑})

這種本人親測

 
        

 

第四種解決方法,就是將 spring boot啟動類方法mapper上級,這樣也可以掃描到

 

工作中出了問題,解決時間太久,記錄一下

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM