从另一个EAR访问本地会话Bean? [英] access a Local Session Bean from another EAR?

查看:112
本文介绍了从另一个EAR访问本地会话Bean?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从另一个EAR中的EAR中调用本地会话Bean?
部署在同一个Glassfish v3域中?

How can I call a Local Session Bean inside an EAR from another EAR, both deployed in the same Glassfish v3 domain?

这是结构:

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。

TestSessionBean implements TestSessionLocal, boths EARs has common.jar.

我需要使用TestSessionBeanClient中的TestSessionBean。我想要获得
优势的本地会话bean,因为性能。

I need to use TestSessionBean from TestSessionBeanClient. I would like to take advantage of local session bean because of performance.

我知道我不能在TestSessionBeanClient中使用一个简单的@EJB调用,所以我尝试
来查找:

I know I can't use a simple @EJB call in the TestSessionBeanClient, so I tried to lookup like this:

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

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

That will throw a ClassCastException because the returned object will not be TestSessionLocal but a proxy class like:

TestSessionLocal_1389930137

要能够调用其methos,我必须做反思来找到它的方法。

that to be able to call its methos I must do reflection to find its methods.

请帮助。

提前谢谢。

推荐答案

根据EJB 3.1规范的3.2.2:

Per 3.2.2 of the EJB 3.1 specification:


通过
访问企业bean本地客户端视图只需要
支持本地客户端
打包在同一个应用程序
作为企业bean,提供
本地客户端视图。符合此规范的
实现
可以可选地支持从打包在
不同应用程序中的本地客户端访问企业
bean的
本地客户端视图。
配置要求
应用程序访问本地
客户端视图是供应商特定的,
不在此
规范的范围之内。依赖
应用程序访问本地
客户端视图的应用程序是不可移植的。

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常见问题:我有一个具有本地界面的EJB组件。可以从不同应用程序的Web组件访问它吗?

Here is the GlassFish FAQ: I have an EJB component with a Local interface. Can I access it from a web component in a different application?

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

(That said, you could try packaging your interface such that it is loaded by a ClassLoader that is common to both applications.)

这篇关于从另一个EAR访问本地会话Bean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆