dubbo同一个接口既包括生产者又包含消费者,导致本地也要写一个实现类,这样就有两个实现类,初始化bean时报错:
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.xxxx.prov.flowchg.OrderResultNoticeSvc com.xxxx.system.modular.group.service.GroupService.orderResultNoticeSvc; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [com.xxxx.prov.flowchg.OrderResultNoticeSvc] is defined: expected single matching bean but found 2: orderResultNotice,orderResultNoticeSvcImpl
搜索了很多答案,引入时用Spring的自动注入@Autowired功能,@Qualifier指定名称依然报错,也用了@Resource注入,问题依旧;
@Autowired(required = false)
@Qualifier("orderResultNoticeSvcImpl")
private OrderResultNoticeSvc orderResultNoticeSvcImpl;
@Qualifier("orderResultNoticeSvcImpl")
private OrderResultNoticeSvc orderResultNoticeSvcImpl;
最后请教其他开发人员,使用set方法注入,成功。
private OrderResultNoticeSvc groupOrderResultNotice;public OrderResultNoticeSvc getGroupOrderResultNotice() {
return groupOrderResultNotice;
}
public void setGroupOrderResultNotice(OrderResultNoticeSvc groupOrderResultNotice) {
this.groupOrderResultNotice = groupOrderResultNotice;
}