【问题标题】:SpringBeanAutowiringInterceptor - Configure to autowire by name instead of by type?SpringBeanAutowiringInterceptor - 配置为按名称而不是按类型自动装配?
【发布时间】:2013-08-14 16:46:46
【问题描述】:

我在 EJB3 无状态会话 bean 中使用 SpringBeanAutowiringInterceptor,如 Spring documentation 中所述。

@Stateless
@Interceptors(SpringBeanAutowiringInterceptor.class)    // Allows spring injection for its setter methods
public class MyClassImpl extends MyAbstractClass implements MyClass 
{
    ....
    @Autowired
    public void setMyCustomService2(MyService svc) {
        this.service = svc;
    }

在 SpringConfig.xml 中:

<bean id="myCustomService1" class="...MyService"/>
<bean id="myCustomService2" class="...MyService"/>

当 Spring 尝试自动装配时,我得到了

No unique bean of type [...MyService ] is defined: 
  expected single matching bean but found 2: [myCustomService1 , myCustomService2]

不幸的是,EJB 自动装配似乎默认为byType 模式,我找不到将其更改为byName 模式的方法。

这可能吗?如果可以,怎么做?

【问题讨论】:

    标签: java spring ejb-3.0 autowired


    【解决方案1】:

    你试过Qualifier吗?

    @Autowired
    @Qualifier("myCustomService1")
        public void setMyCustomService2(MyService svc) {
        this.service = svc;
    }    
    

    【讨论】:

      猜你喜欢
      • 2021-12-29
      • 2012-03-29
      • 2012-08-03
      • 2014-09-29
      • 2012-05-06
      • 1970-01-01
      • 1970-01-01
      • 2011-05-25
      • 2012-12-13
      相关资源
      最近更新 更多