SpringBoot整合mybatisPlus-代碼生成器錯誤和yaml常見錯誤


SpringBoot整合MyBatis錯誤總結

背景:4月5號中午,終於學完了SpringBoot的基本路線!休息幾個小時,趁機會把SpringBoot的踩坑出坑記錄一下

ps: 大神勿噴

 

 


 

錯誤:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'articleServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.xx.blog.mapper.ArticleMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

 
 

錯誤場景:使用mybatisPlus代碼生成器,通過數據庫逆向生成代碼。導致代碼報錯

解決方案:

在生成的 mapper 接口上添加注解@Mapper 或 在啟動類上添加注解 @MapperScan("mapper包名")

 

或者

 

推薦:

推薦在SpringBoot的啟動類上添加注解@MapperScan("mapper包名") 一勞永逸 不然需要在所有的mapper接口上添加注解 @Mapper

 

 

 


   

 

 

錯誤:

Description:

A component required a bean of type 'com.xx.blog.mapper.ArticleMapper' that could not be found.

Action:

Consider defining a bean of type 'com.xx.blog.mapper.ArticleMapper' in your configuration.

Process finished with exit code 0

 

錯誤場景: 在解決上面的錯誤之后又出現的錯誤 , 組件需要找不到“com.xx.blog.mapper.ArticleMapper”類型的bean。

解決方案:

 

添加了@Mapper注解之后這個接口在編譯時會生成相應的實現類

需要注意的是:這個接口中不可以定義同名的方法,因為會生成相同的id

也就是說這個接口是不支持重載的 

 

 


 

 

 


 
 
 
 

錯誤 :

java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.yml

錯誤場景:application.yml 就是一個大坑,如果出現以上情況,一般就是application.yml這個文件中有語法錯誤。

解決方案:

注釋錯誤引起(application.yml采用的是#注釋而不是//,而且# 后面必須跟一個空格)

縮進采用空格,千萬不要用tab

每個冒號后面一定要有一個空格否則會報錯

 

 


免責聲明!

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



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