我有一个多耳项目。一些 EJB 驻留在 project1.ear 中,我需要在 project2.ear 中使用它。
我正在尝试以下操作:
@Remote
public interface MyService {
public static final String JNDI_NAME = "service/MyService";
// methods
}
@Stateless(name = MyService.JNDI_NAME, mappedName = MyService.JNDI_NAME)
public class MyServiceImpl implements MyService {
// implementations...
}
然后,在一些 project2.ear 类中,我像这样注入 EJB:
@Stateless(name = "other/Service")
public class OtherServiceImpl implements OtherService{
@EJB(mappedName = MyService.JNDI_NAME)
private MyService service;
}
但是我得到了很多“FailedToConstructException”和 EJB 相关的异常,原因如下:
Caused by: javax.naming.NameNotFoundException: service/MyService -- service jboss.naming.context.java.service.MyService
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:113)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214)
at javax.naming.InitialContext.lookup(InitialContext.java:411) [rt.jar:1.7.0_05]
at org.jboss.as.ejb3.deployment.processors.EjbLookupInjectionSource$1.getReference(EjbLookupInjectionSource.java:82) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
... 104 more
我究竟做错了什么?
提前致谢。