Java – JNDI lookup of EJB3 in ear file on GlassFish

I have an ear file containing a large number of jars, one of which contains local session beans (EJB3) I need to perform JNDI lookup of these session beans from unmanaged POJOs, which are also included in the ear (in this case, the same as jars in EJBs) I tried to follow GlassFish EJB FAQ, but no matter what I tried, I will continue to receive javax naming. NameNotFoundException.

I'm not sure about something Where should I put my EJB jar XML (I tried ears meta inf and jars meta INF)? I need sun EJB jar XML? What exactly is EJB link and what does it do? What might I have done wrong (my configuration is almost the same as the local lookup given in the FAQ)?

I listed some configurations I tried and the results are as follows:

<enterprise-beans>
  <session>
    <ejb-name>ITestBean</ejb-name>
    <ejb-class>com.test.TestBean</ejb-class>
    <ejb-local-ref>
      <ejb-ref-name>ITestBean</ejb-ref-name>
      <local>com.test.ITestBean</local>
    </ejb-local-ref>
  </session>
 </enterprise-beans>

Application deployment but JNDI lookup returned null

<enterprise-beans>
  <session>
    <ejb-name>ITestBean</ejb-name>
    <ejb-class>com.test.TestBean</ejb-class>
    <ejb-local-ref>
      <ejb-ref-name>ITestBean</ejb-ref-name>
      <local>com.test.ITestBean</local>
      <ejb-link>ITestBean</ejb-link>
    </ejb-local-ref>
  </session>
 </enterprise-beans>

Application not deployed: unable to determine the local business and remote business assignment of unresolved EJB ref itestbean @ JNDI for EJB 3.0 Ref

<enterprise-beans>
  <session>
    <ejb-name>ITestBean</ejb-name>
    <ejb-class>com.test.TestBean</ejb-class>
    <ejb-local-ref>
      <ejb-ref-name>ITestBean</ejb-ref-name>
      <local>com.test.ITestBean</local>
      <ejb-link>MyJar.jar#ITestBean</ejb-link>
    </ejb-local-ref>
  </session>
 </enterprise-beans>

Application not deployed: error: unresolved: myjar jar#ITestBean.

<enterprise-beans>
  <session>
    <ejb-name>ITestBean</ejb-name>
    <local>com.test.ITestBean</local>
    <ejb-local-ref>
      <ejb-ref-name>ITestBean</ejb-ref-name>
    </ejb-local-ref>
  </session>
 </enterprise-beans>

Error processing ejbdescriptor

Solution

You can always use system Out or dump all names in initialcontext in the log

//Get all the names in the initial context
NamingEnumeration children = initialContext.list("");

while(children.hasMore()) {
    NameClassPair ncPair = (NameClassPair)children.next();
    System.out.print(ncPair.getName() + " (type ");
    System.out.println(ncPair.getClassName() + ")");
  }
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>