Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
540 views
in Technique[技术] by (71.8m points)

java - access a Local Session Bean from another EAR?

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

This is the structure:

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 implements TestSessionLocal, boths EARs has common.jar.

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

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");

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

TestSessionLocal_1389930137

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

Please help.

Thank you in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Per 3.2.2 of the EJB 3.1 specification:

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.

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?

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...