java - SpringBeanAutowiringInterceptor - 配置为按名称而不是按类型 Autowiring ?

标签 java spring ejb-3.0 autowired

我在 EJB3 无状态 session 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 尝试 Autowiring 时,我得到

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

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

这可能吗?如果可能的话,如何实现?

最佳答案

您是否尝试过使用限定符

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

关于java - SpringBeanAutowiringInterceptor - 配置为按名称而不是按类型 Autowiring ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18237610/

相关文章:

java - 使用Hibernate使用的Javassist实体类进行检测

Java - ExecutorService 有最大尺寸

java - Spring Security - 持久记住我的问题

java - 将 EJB 3 部署为单独的项目并通过 Websphere 7 中的 servlet 进行访问

java - 领先的 EJB 平台提供商有哪些,例如 WebSphere 等?

ejb-3.0 - 我从设置这个 TransactionAttributeType.NOT_SUPPORTED 得到什么

java - Jasypt 1.9 : Encrypting passwords with exclamation

java - 通过java访问json最里面的值

java - CXF Servlet API方法列出所有服务bean?

java - Spring MVC @RequestMapping 参数问题