-2

SpringBeanAutowiringInterceptor在 EJB3 无状态会话 bean 中使用 a,如Spring 文档中所述。

@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模式的方法。

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

4

1 回答 1

4

Have you tried with a Qualifier?

@Autowired
@Qualifier("myCustomService1")
    public void setMyCustomService2(MyService svc) {
    this.service = svc;
}    
于 2013-08-14T17:15:26.883 回答