Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EJB - Lookup failed for 'ejb/BookRequestBean'

I am new to EJB, and was trying "Hello World" type of EJB Java program. Here is my EJB:

package dukesbookstore.ejb;
@Stateless(name="BookRequestBean", mappedName="ejb/BookRequestBean")
@Named
public class BookRequestBean {
    //Other codes here
}

and here is my client:

    Properties prop = new Properties();
    prop.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
    prop.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
    prop.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
    try {
        InitialContext ctx = new InitialContext(prop);                              
        ctx.lookup("ejb/BookRequestBean");
        System.out.println("EJB Look-up successfull!!");
    } catch (NamingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

But whenever I try to run, I am getting below exception:

javax.naming.NamingException: Lookup failed for 'ejb/BookRequestBean' in SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=localhost, java

I have added appserv-rt.jar , gf-client.jar, javaee.jar, but still no luck. Can anyone help me, what I am missing here? I am usign Glassfish 3.1

like image 411
Pradeep Simha Avatar asked May 10 '13 11:05

Pradeep Simha


2 Answers

There can be several reasons to this:

1) Your EJB is not mapped to JNDI name. You need to check whether your EJB is deployed successfully and it is mapped to JNDI name. You can check Server GUI, Server Log on startup or use Universal Test Client to see if EJB is mapped correctly. Note, UTC will only show Remotely exposed EJBs.

2) Your EJB is only exposed to Local application. In this case, Remote call or Cross application call(different EAR, WAR...) to your EJB will fail. In this scenario, create Remote interface and expose it. Local interface exposes EJB to only local calls. Remote interface exposes EJB to remote or cross application calls.

3) Your RMI/IIOP port may be incorrect. You can check Glassfish GUI or Server startup log to see what port RMI/IIOP is assigned to.

Note: To diagnose the exact problem, please post full stack trace.

like image 92
Ravi Trivedi Avatar answered Sep 21 '22 12:09

Ravi Trivedi


In addition to nice @RaviTrivedi answer, here are few thoughts:

  • @Named annotation shouldn't be used this way
  • don't use both name and mappedName, for Glassfish it is enough to use just mappedName
  • your EJB should implement remote interface
like image 22
Miljen Mikic Avatar answered Sep 22 '22 12:09

Miljen Mikic