Looking up an EJB dynamically

百般思念 提交于 2019-12-13 16:23:02

问题


I'm developing an application on Glassfish 3. I have an EJB that looks like this:

@LocalBean
@Stateless
public class MyBean {
  public void doSomething() {}
}

My client code (running inside the same application) looks like this:

MyBean mb = (MyBean) InitialContext.doLookup(MyBean.class.getName());

According to a few sources, this should be a valid lookup method, but it throws a NameNotFoundException. What am I doing wrong?


回答1:


According to what sources? I would personally use portable JNDI names specified in EJB 3.1. See:

  • Portable Global JNDI names by Mahesh Kannan
  • What is the syntax for portable global JNDI names in EJB 3.1? in GlassFish's EJB FAQ
  • Portable Global JNDI Names by Ken Saks
  • Application-specified Portable JNDI Names by Ken Saks

Depending on the packaging, I would use a module-scoped or an application-scoped JNDI name.

BTW, GlassFish logs the portable JNDI names at deployment time.



来源:https://stackoverflow.com/questions/3402317/looking-up-an-ejb-dynamically

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