java - 从另一个 EAR 访问本地 session Bean?

标签 java session ejb glassfish-3 ear

如何从另一个 EAR 调用一个 EAR 内的本地 session Bean,既 部署在同一个 Glassfish v3 域中?

这是结构:

Glassfish v3 Domain1

    EAR1
            EAR1-EJB.jar
                    class TestSessionBean           <-- @Stateless
            common.jar
                    interface TestSessionLocal      <-- @Local

    EAR2
            EAR2-EJB.jar
                    class TestSessionBeanClient     <-- @Singleton, @LocalBean
            common.jar
                    interface TestSessionLocal      <-- @Local

TestSessionBean 实现了 TestSessionLocal,两个 EAR 都有 common.jar。

我需要使用 TestSessionBeanClient 中的 TestSessionBean。我想带 本地 session bean 的性能优势。

我知道我不能在 TestSessionBeanClient 中使用简单的 @EJB 调用,所以我尝试了 像这样查找:

InitialContext ic = new InitialContext();
TestSessionLocal tsl = ic.lookup("java:global/EAR1/EAR1-EJB/TestSessionBean!org.test.TestSessionLocal");

这将抛出 ClassCastException 因为返回的对象不会 TestSessionLocal 而是一个代理类,例如:

TestSessionLocal_1389930137

为了能够调用它的方法,我必须进行反射以找到它的方法。

请帮忙。

提前谢谢你。

最佳答案

根据 EJB 3.1 规范的 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.

这是 GlassFish 常见问题解答:I have an EJB component with a Local interface. Can I access it from a web component in a different application?

(也就是说,您可以尝试打包您的界面,使其由两个应用程序通用的 ClassLoader 加载。)

关于java - 从另一个 EAR 访问本地 session Bean?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5681197/

相关文章:

java - Spring Cloud Config使用git从本地gitlab获取配置失败

java - MyBatis:如何返回列表映射?

java - 端口 80 上的 Tomcat Web 应用程序

nhibernate - 如何从 CaSTLe ActiveRecord SessionScope 检索当前的 NHibernate Session 对象

java - 从 Jboss7 迁移到 WildFly10 后,WebContext 不再受支持

java - EJB 是否需要专用服务器才能使用?

java - Wicket 破解了 ListView 的使用,有哪些替代方案?

java - 当2个tomcat在不同的机器上时,如何在tomcat中实现负载均衡器?

java - 将值从 Java 操作类传递到 ejb?

java - 如何让 session 不超时?