我有这样的界面:
@Local
public interface MyInterface {
}
和两个实现此接口的类:
@Singleton
public class FirstBean implements MyInterface {
}
@Singleton
public class SecondBean implements MyInterface {
}
还有另一个类似下面的类:
@Singleton
public class ThirdBean {
@EJB
private MyInterface xpto;
}
我在部署时收到以下错误:
找到多个具有绑定类型接口的ejb
如何解决?
答案 0 :(得分:2)
尝试使用qalifier
@java.lang.annotation.Documented
@java.lang.annotation.Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE,ElementType.FIELD})
@javax.inject.Qualifier
public @interface First {
}
使用此限定符标记bean
@Singleton
@First
public class FirstBean implements MyInterface {
}
然后注入
@Singleton
public class ThirdBean {
@Inject
@First
private MyInterface xpto;
}