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

编程入门 行业动态 更新时间:2024-10-28 16:16:01

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

更多推荐

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

本文发布于:2023-06-14 23:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/716238.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:画蛇添足   千万不要   dependency   Unsatisfied   expressed

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!