各位小伙伴千万别画蛇添足。使用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