@Autowired 注入 xxx required a single bean, but 2 were found xxx
Description:
Field oidGanerator in com.ats.dt.service.impl.KnwNoumenonServiceImpl required a single bean, but 2 were found:
- OIDGanerator: defined in file [E:\AAA\dataManager\data-api\target\classes\com\ats\dt\util\OIDGanerator.class]
- oIDGanerator: defined by method 'oIDGanerator' in class path resource [com/ats/dt/config/DtRedissonConfig.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 但是出现了两个
解决方案:考虑将其中一个Bean标记为@Primary,更新使用者以接受多个Bean,或使用@Qualifier标识应使用的Bean
@Autowired注入规则
默认先按照Type注入,如果同一个Type找到多个bean,则又按照name方式对比,如果有多个则会报出异常。
解决方法:
还没有评论,来说两句吧...