@Autowired 注入 xxx required a single bean, but 2 were found xxx

清疚 2023-10-05 20:30 100阅读 0赞
  1. Description:
  2. Field oidGanerator in com.ats.dt.service.impl.KnwNoumenonServiceImpl required a single bean, but 2 were found:
  3. - OIDGanerator: defined in file [E:\AAA\dataManager\data-api\target\classes\com\ats\dt\util\OIDGanerator.class]
  4. - oIDGanerator: defined by method 'oIDGanerator' in class path resource [com/ats/dt/config/DtRedissonConfig.class]
  5. Action:
  6. 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 但是出现了两个
解决方案:考虑将其中一个Bean标记为@Primary,更新使用者以接受多个Bean,或使用@Qualifier标识应使用的Bean

@Autowired注入规则
默认先按照Type注入,如果同一个Type找到多个bean,则又按照name方式对比,如果有多个则会报出异常。
解决方法:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,100人围观)

还没有评论,来说两句吧...

相关阅读