如何从另一个 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/