Skip to main content

EJB Local interface lookup through helper classes

1 reply [Last post]
Joined: 2006-02-27


I have an EJB with two local/remote interfaces
(following Sahoo's suggestion on thread 13366)

public interface Foo {...

public interface LocalFoo extends Foo{}
public interface RemoteFoo extends Foo{}

public class FooBean implements Foo {

Through helper classes I try to do:

Context ic = new InitialContext();
LocalFoo lf = (LocalFoo) ic.lookup(LocalFoo.class.getName());

But I get a Naming exception that LocalFoo was not found,

I assume this is because Glassfish does not register the LOCAL interface automatically, by following this thread:

Following Sahoo's
response over this thread:

"I suspect it is to do with some ease of use feature in GlassFish where GlassFish is automatically defining a JNDI name and making the remote ejb available where as it is not doing the same for the local ejbs."

Yet again, I have an EJB that calls a helper class and I try from the helper class to lookup over the Local interface of another EJB,

And I must mention, injecting the local interface of the EJB with @EJB annotation by another EJB works fine, I only get the naming exception while trying to use JNDI lookup thorugh helper classes!

Thanks in advanced,

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2005-03-30

Your assumption about GlassFish not registering localinterface of the EJB in the JNDI is correct and that's why your JNDI lookup is not working. As I suggested in
either you use ejb-ref (you actually said, you don't like XML DD) or use @EJB to annotate one of the client EJBs in the ejb-jar file.

-- Sahoo