Frage

I've an EAR app contains two modules.

EJB Module and Web Module.

In web module, I am trying to get a ref to some EJB SLSB, I don't use injection cause the class the I need to invoke the method in is not managed.

I am using the following code from the web module:

IFooBarService service = InitialContext.doLookup("IFooBarService");

IFooBarService: the the Local Interface that defined as ( in the ejb module):

@Local
public interface IFooBarService
{
    // ...
}

Do I miss something? (should I supply environment info?)

War es hilfreich?

Lösung 2

From Here: https://forums.oracle.com/forums/thread.jspa?threadID=476903

The solution is:

fooBarService = (FooBarService) ((StatelessSessionDefaultLocalHome)
    new InitialContext().lookup("EJBModuleName_FooBarServiceLocal")).create();

Andere Tipps

Are you sure that IFooBarService is the JNDI name the IFooBarService service is bound to? JBoss for example shows the JNDI names in the boot log. You can then use it for lookup purposes.

In general, if you want your app to be portable you shouldn't rely on the server mechanism to generate JNDI names, as the Java EE spec has its own. You should be able to do:

IFooBarService service = InitialContext.doLookup("java:comp/env/IFooBarService");

If you are using newer versions of Java EE (Java EE 6), and want to lookup an EJB which is in the same app but in a different module, you can do:

IFooBarService service = InitialContext.doLookup("java:app/[module name]/IFooBarService");

More info on standard names here.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top