EJB - Search failed for 'ejb / BookRequestBean'

I am new to EJB and trying to use Hello World for Java EJB. 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 get below exception:

javax.naming.NamingException: Failed to search 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 added appserv-rt.jar , gf-client.jar , javaee.jar , but still no luck. Can anyone help me, what am I missing here? I am using Glassfish 3.1

+6
source share
3 answers

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

  • @Named annotation should not be used this way
  • do not use both name and mappedName , for Glassfish it is enough to use only mappedName
  • your EJB must implement the remote interface
+2
source

There may be several reasons:

1) Your EJB not mapped to a JNDI name. You need to check if EJB deploying successfully and map to the JNDI name. You can check the Server GUI , Server Log on startup or use the Universal Test Client to see if the EJB displayed correctly. Note. UTC will only show remote EJBs.

2) Your EJB is available only for the local application. In this case, a call to a remote call or a cross-application (different EARs, WARs ...) to your EJB will fail. In this case, create a remote interface and publish it. The local interface provides EJB only for local calls. The remote interface provides EJBs for remote or cross-application calls.

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

Note. . To diagnose the exact problem, send full stack statistics.

+6
source

By adding to @Ravi Trivedi and @Miljen Mikic, if you use Glassfish, you should check how your EJB is registered in JNDI. For example, in Glassfish, enter the following command:

  asadmin list-jndi-entries 
+2
source

Source: https://habr.com/ru/post/944706/


All Articles