其他分享
首页 > 其他分享> > mybatis-plus 报错 Unsatisfied dependency expressed through field ‘XXXMapper‘;

mybatis-plus 报错 Unsatisfied dependency expressed through field ‘XXXMapper‘;

作者:互联网

报错如下:

Unsatisfied dependency expressed through field 'XXXMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.XXX.XXXX.mapper.XXXMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:660) ~[spring-beans-5.3.8.jar:5.3.8]

实测 在主启动类加
MapperScan注解 最好写成如下形式

@MapperScan("com.XXX.*.xml)

最离谱的是,一开始加了MapperScan 没写括号内容,报错;加了之后成功;成功后删除括号内容,仍然成功…简直玄学
此外配置里的

mybatis-plus.mapper-locations=classpath:/mapper/*.xml

和用了BaseMapper的接口上的 @Mapper 注解 也都可以注释掉,仍然可以成功启动…
果然代码跑起来了 就别管他怎么跑起来的了…

标签:Unsatisfied,mapper,factory,springframework,field,报错,org,beans
来源: https://blog.csdn.net/weixin_41421576/article/details/118490658