4 Replies Latest reply on Nov 4, 2014 9:27 AM by wilddev

    Cannot lookup the EJB3 bean - NameNotFound exception

    wilddev

      The server side contains the only interface and bean @Remote and @Stateless annotated.

      Has ran on WildFly successfully, i can see deployed beans from WildFly console.

      It's hints to me uri for JNDI bindings:

      java:app/server_ejb/DeployBean!interfaces.Deploy

      But i can't connect to this!

      So my client is:

      Initial context properties:

      Context.INITIAL_CONTEXT_FACTORY=org.jboss.naming.remote.client.InitialContextFactory Context.PROVIDER_URL=http-remoting://localhost:8080

      Client:

      Properties props = new Properties(...); InitialContext ctx = new InitialContext(props); Deploy bean = (Deploy) ctx.lookup("java:app/server_ejb/DeployBean!interfaces.Deploy"); bean.sayHi();

      I get an exception:

      INFO: JBoss Remoting version (unknown) Exception in thread "main" javax.naming.NameNotFoundException: app/server_ejb/DeployBean!interfaces.Deploy -- service jboss.naming.context.java.jboss.exported.app.server_ejb."DeployBean!interfaces.Deploy" at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:104)

      Whats wrong?

        • 1. Re: Cannot lookup the EJB3 bean - NameNotFound exception
          wdfink

          How you deploy the application? From the log it looks like your client is a standalone application.

          If it is a jar the lookup should be "/server_ejb/DeployBean!interfaces.Deploy"

          If it is a ear you need to add the ear's name as prefix.

          • 2. Re: Cannot lookup the EJB3 bean - NameNotFound exception
            wilddev

            Actually yes, it's standalone. Shouldn't be?

            I packaged this as .jar, pointing native jboss-client.jar lib and server_ejb artifact as dependencies; and ran it in Application mode.

            • 3. Re: Cannot lookup the EJB3 bean - NameNotFound exception
              wdfink

              No the client can be a standalone java application.

              Only the lookup depends on the server deployment.

              In any case "java:" prefix does not work for a standalone application.

               

              In your case you should see a server side logging which contain a JNDI binding like this one:

                 java:jboss/exported/jboss-ejb-multi-server-app-main/ejb/MainAppSContextBean!org.jboss.as.quickstarts.ejb.multi.server.app.MainApp

              You need to use the name behind exported "jboss-ejb-multi-server-app-main/ejb/MainAppSContextBean!org.jboss.as.quickstarts.ejb.multi.server.app.MainApp".

              This example is an ear deployment jboss-ejb-multi-server-app-main.ear.

              If you have a simple jar as deployment the JNDI name would start with /ejb if you deploy an ejb.jar.

               

              For more informations see Remote EJB invocations via JNDI

              Notice that this approach is not recommended for EJB invocations (see restrictions in previous link), you should use EJB invocations from a remote client using JNDI

              • 4. Re: Re: Cannot lookup the EJB3 bean - NameNotFound exception
                wilddev

                It has been fixed by adding

                jndiProps.put("jboss.naming.client.ejb.context", true);

                to the properties and changing lookup string to the relative like this:

                .lookup("/server_ejb/DeployBean!interfaces.Deploy").

                 

                wfink, thank you for help