2

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?

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
Mike Baranczak
  • 8,291
  • 8
  • 47
  • 71

1 Answers1

2

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

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.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • 1
    My sources: http://www.devx.com/tips/Tip/35010 and http://www.roseindia.net/ejb/ejb-lookup.shtml. Seems that both of them are completely full of shit. – Mike Baranczak Aug 04 '10 at 13:19
  • 2
    @Mike Prior to EJB 3.1, JNDI names were not standardized so there is no general rule, JNDI names are app server dependent. PS: I tend to ignore roseindia and devx "tech tips", I don't consider them as high quality resources. – Pascal Thivent Aug 04 '10 at 14:01