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

 ̄綄美尐妖づ 提交于 2019-12-05 07:24:00
lindelof

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!