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实体类上添加注解@Repository 将Mapper交给Spring管理

 

 


错误 :

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

错误场景:application.yml 就是一个大坑,如果出现以上情况,一般就是application.yml这个文件中有语法错误。

解决方案:

注释错误引起(application.yml采用的是#注释而不是//,而且# 后面必须跟一个空格)

缩进采用空格,千万不要用tab

每个冒号后面一定要有一个空格否则会报错

 

 

猜你喜欢

转载自www.cnblogs.com/kkdaj/p/12638909.html