开发者

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

开发者 https://www.devze.com 2022-12-21 19:48 出处:网络
In Weblogic 10.3, how do I inject a remote EJB from one EAR into a Stateless bean of another, both EARs being deployed in the same container? Ideally I\'d like to do as much as possible with annotatio

In Weblogic 10.3, how do I inject a remote EJB from one EAR into a Stateless bean of another, both EARs being deployed in the same container? Ideally I'd like to do as much as possible with annotations.

So suppose I have the following interface:

public interface HelloService {
  public String hello();
}

implemented by the following EJB:

@Stateless
@Remote
public class Hell开发者_运维百科oServiceBean implements HelloService {
  public String hello() {
      return "hello";
  }
}

Suppose they're packaged and deployed in 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 figures out the wiring correctly between HelloClientBean in client.ear and HelloServiceBean in server.ear? Pointers to official documentations and/or books warmly welcome.


The easiest solution I've found so far is the following.

First, annotate the stateless bean with a mappedName attribute:

@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 a JNDI name is given as the mappedName attribute (or in the deployment descriptor, or in a proprietary annotation).

Next, you can now annotate your client field with @EJB with a mappedName attribute, which should be the same as the attribute on the server bean. (I am honestly baffled by this. NameNotFoundException when calling a EJB in Weblogic 10.3 suggests that I should be able to use the mappedName#interfaceName syntax, but in my tests this doesn't work.):

@Stateless
public class HelloClientBean {
    @EJB(mappedName="HelloService")
    HelloService helloService;

// other methods...
}

This now works, as long as both EARs are deployed in the same container. Next I'll try to figure out the right syntax when they are deployed on different machines.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号