Unsatisfied dependency expressed through field dao,千万不要画蛇添足

各位小伙伴千万别画蛇添足。使用Springboot的时候。当你想用两个数据库查询两张表提高数据库的性能,你可千万得看好了

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'teacherGradeController': Unsatisfied dependency expressed through field 'service'; 
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'teacherGradeServiceImpl': Unsatisfied dependency expressed through field 'dao'; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'com.qf.dao.TeacherGradeDao' available: expected single matching bean but found 2: teacherGradeDaoImpl,teacherGradeDao

Description:

Field dao in com.qf.service.Impl.TeacherGradeServiceImpl required a single bean, but 2 were found:
	- teacherGradeDaoImpl: defined in file [E:\Protect\springboot\springbootInterceptor\target\classes\com\qf\dao\Impl\TeacherGradeDaoImpl.class]
	- teacherGradeDao: defined in file [E:\Protect\springboot\springbootInterceptor\target\classes\com\qf\dao\TeacherGradeDao.class]


Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

这个错误,其实就在你的启动类,一方面是看看放在哪里,你如果放在子包里则他不会扫描的,比如放在(bean,service。。。)这种的父包,他才会扫描这个。
还有一种就是你是不是在启动类中写入 @MapperScan(dao层) 这个玩意,千万别写,这个注解的意思就是扫描dao层包的接口,因为你在这个查询两个数据库的时候,他是有dao层的实现类的,你在扫描dao接口的注解你肯定找不到,所以方法就是 删除再启动类中写的 @MapperScan 就OK了

@Primary 这个是标明哪个是主库
如果是双数据库的话 最好是在每个dao层上面写上 @Mapper

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值