EJB:@Local 调用另一个 EAR

EJB: @Local invocation to another EAR

我正在使用 EJB 3.1 和 Wildfly 8。2.Final

耳朵 1:

jar-impl with Bean1 (where I execute the lookup of Interface2)

lib /
    jar with Interface2

耳朵 2:

jar-impl with Bean2

lib / 
    jar with Interface2 and META-INF/ejb-jar.xml

我想在注解为@Local 的Interface2 的Bean1 中执行查找。

"Look up"代码:

Properties jndiProp = new Properties();
InitialContext ctx = new InitialContext(jndiProp);
Object bean = ctx.lookup(JNDI);
Interface2 interface = (Interface2) bean;

如果我用@Remote 注释 Interface2,启动时的 wildfly 会写:

    java:global/c4c.commons.backend/c4c.commons.backend-impl/Bean2!eu.dedalus.c4c.commons.service.Interface2
    java:app/c4c.commons.backend-impl/Bean2!eu.dedalus.c4c.commons.service.Interface2
    java:module/Bean2!eu.dedalus.c4c.commons.service.Interface2
    java:jboss/exported/c4c.commons.backend/c4c.commons.backend-impl/CMSRemoteServiceBean!eu.dedalus.c4c.commons.service.Interface2
    java:global/c4c.commons.backend/c4c.commons.backend-impl/Bean2
    java:app/c4c.commons.backend-impl/Bean2
    java:module/Bean2

拥有

JNDI = "ejb:c4c.commons.backend/c4c.commons.backend-impl/Bean2!eu.dedalus.c4c.commons.service.Interface2"

一切顺利..但是当我用@Local 注释 Interface2 是我想做的事情时,启动时的 wildfly 写道:

java:global/c4c.commons.backend/c4c.commons.backend-impl/Bean2!eu.dedalus.c4c.commons.service.Interface2
    java:app/c4c.commons.backend-impl/Bean2!eu.dedalus.c4c.commons.service.Interface2
    java:module/Bean2!eu.dedalus.c4c.commons.service.Interface2
    java:global/c4c.commons.backend/c4c.commons.backend-impl/Bean2
    java:app/c4c.commons.backend-impl/Bean2
    java:module/Bean2

请参阅 EJB 3.x 规范进行说明,例如EJB 3.2 规范第 3.2.2 节:

Access to an enterprise bean through the local client view is only required to be supported for local clients packaged within the same application as the enterprise bean that provides the local client view. Compliant implementations of this specification may optionally support access to the local client view of an enterprise bean from a local client packaged in a different application. The configuration requirements for inter-application access to the local client view are vendor-specific and are outside the scope of this specification. Applications relying on inter-application access to the local client view are non-portable.

使用远程接口通常需要对方法参数和返回对象进行编组和解组,以及明确的类加载器分离。

如果您需要从另一个 JVM(例如远程客户端)或同一应用程序服务器中的另一个应用程序范围进行访问,请使用远程 EJB。如果您只想在您的应用程序范围内提供对 EJB 的访问,请使用本地 EJB。