How can I call a remote EJB in an EAR from another?

In Weblogic 10.3, how can I insert a remote EJB from one EAR into the idle bean of the other, both EARs deployed in the same container? Ideally, I would like to make as many annotations as possible.

So, suppose I have the following interface:

public interface HelloService { public String hello(); } 

implemented by the following EJB:

 @Stateless @Remote public class HelloServiceBean implements HelloService { public String hello() { return "hello"; } } 

Suppose they are packaged and deployed to server.ear . Now in client.ear I have the following:

 @Stateless public class HelloClientBean { @EJB HelloService helloService; // other methods... } 

What do I need to add so that Weblogic correctly defines the wiring between HelloClientBean in client.ear and HelloServiceBean in server.ear ? Pointers to official documentation and / or books are warmly welcome.

+6
java-ee ejb weblogic
source share
1 answer

The easiest solution I have found so far is the following.

First annotate the idle bean attribute mappedName :

 @Stateless(mappedName="HelloService") @Remote public class HelloServiceBean implements HelloService { public String hello() { return "hello"; } } 

According to http://forums.oracle.com/forums/thread.jspa?threadID=800314&tstart=1 , Weblogic will never create a JNDI entry for an EJB unless the JNDI name is specified as a mappedName attribute (either in the deployment descriptor or in the proprietary annotation )

Then you can now annotate your @EJB client field with the @EJB attribute, which should be the same as the attribute on the bean server . (I'm honestly puzzled by this. A NameNotFoundException when calling an EJB in Weblogic 10.3 assumes that I should use the mappedName#interfaceName syntax, but this does not work in my tests.):

 @Stateless public class HelloClientBean { @EJB(mappedName="HelloService") HelloService helloService; // other methods... } 

Now this works while both EARs are deployed in the same container. Then I will try to figure out the correct syntax when they are deployed to different machines.

+4
source share

All Articles