用MybtisPlus的代码生成器生成了impl,只在yml里配置了mapper的包路径,以及在主启动类上加了@MapperScan("mapper包路径"),启动,就报这个错,一直报这个错。
错误信息:
1.org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'stuInfoScoreController': Unsatisfied dependency expressed through field 'stuInfoScoreService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'stuInfoScoreServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.jianglina.peixuncore.mapper.StuInfoScoreMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2.Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'stuInfoScoreServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.jianglina.peixuncore.mapper.StuInfoScoreMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
3.NoSuchBeanDefinitionException: No qualifying bean of type 'com.peixuncore.mapper.StuInfoScoreMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
用过很多方法:
1.pom里的依赖版本问题 ——改的跟别人运行成功的版本一样也没用
2.在impl上写@Service("stuInfoScoreServiceImpl")或者@Service("stuInfoScoreService")——不好使
3.mapper路径——没问题
4.能在网上搜到的办法)——都不好使
困住我好几天了 我甚至连代码生成器都核对了好几遍 重写了好多遍还是这个问题 啥也不写就报这个错
在里面想注入个mapper也注入不进来
我不知道原因 也不知道咋解决,求指点。
StuInfoScoreMapper这个类没有被注入成bean,导致依赖注入失败。
StuInfoScoreMapper类上面加入@Mapper注解试一下。
//这样配置加上basePackages
@MapperScan(basePackages = "包路径配置")
你看下mapper和service中是不是少了注解 @service或者@mapper
Mapper注解 mapperScann注解
如果是springboot的话,还要注意包结构,启动类丢到最外面,才会被容器扫描到
模板引擎的依赖也要导入,不然运行会报错的,
还是不懂的话,私信我
谢谢各位指点,让我也丰富了我的知识库。
后来我找到问题了。pom中引用了mybatisplus-spring-boot-starter ,应该是mybatis-plus-boot-starter,同时@MapperScan不管用,需要在mapper上注入@Mpper
最后成功了。
但是不了解:1.那两个依赖有啥区别,为啥前者就一直不能将mapper的bean注入,我上网搜,发现前者在2017年之后已经不更新了。所以不能用了??
2.这两个依赖到底有啥区别???为啥用了后者,@MapperScan就不管用了 ??
希望有懂这方面的前辈在这条评论下指点指点,谢谢