首页 > 编程语言 > 详细

Spring 同一接口注入多个bean实现

时间:2018-06-21 12:19:07      阅读:300      评论:0      收藏:0      [点我收藏+]

如果同一个接口有多个bean实现类,spring在运行时会出现如下异常

required a single bean, but 2 were found:
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

@Primary的意思是在众多相同的bean中,优先使用用@Primary注解的bean.而@Qualifier这个注解则指定某个bean有没有资格进行注入。

@Component
@Primary

 

@Autowired

 

@Component

@Qualifier("fjaoidfj")

 

@Autowired

@Qualifier("fjaoidfj")

 

Spring 同一接口注入多个bean实现

原文:https://www.cnblogs.com/yangfei-beijing/p/9208300.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!