ssm整合mapper注入错误 Unsatisfied dependency expressed through field 'xxxxMapper'; No qualifying bean of type 'xxxxxxx.xxxxMapper' available

抛出的异常

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

我是把之前的项目直接复制了一份 改了项目名称 一开始并没有进行启动 而是写了部分业务逻辑进行单元测试后整体跑程序的时候发现问题,错误是XXXService中自动注入的XXXmapper为空;

 

 

单元测试 通过@ContextConfiguration(locations ={})把所有的配置文件加载进入 测试有效

所以问题在于没有把spring-mybatis的配置文件托管给spring容器 并没有获取到

有重新检查了spring-mybatis的配置文件 里面使用了spring的配置类的自动包扫描,路径无误

再检查的过程中发现一个和正常运行的项目一个不一样的地方

这个是不能运行的项目

 

 

正常运行的项目

 

 

怎么跑成功的 ?

1.把仓库直接删除了 pom文件重新下载

2.新建一个项目 把所有的文件移动过去

3、重新建配置文件

 

由于之后多次建立项目测试 都是无法跑成功 删除maven仓库后跑成功 可能是如某位老哥说的 maven仓库被污染了的原因 但我也不是很懂 不知道到底是maven还是idea的原因

posted @ 2022-07-05 09:42  马里奥爱蘑菇  阅读(441)  评论(0编辑  收藏  举报