5 Replies Latest reply on Jul 18, 2007 3:08 PM by dgdwinte

    Stateless session bean not bound

    dgdwinte

      Hi,

      back with another question: using JBoss 5 beta2, i cannot find my first stateless session bean using a JNDI-lookup from a servlet:

      
       try{
       Context jndiContext=getInitialContext();
       Context ejbCtx = (Context) jndiContext.lookup("java:comp");
       ArticleManagerLocal artman= (ArticleManagerLocal) ejbCtx.lookup("ArticleManager/local");
       PrintWriter out=res.getWriter();
       out.println("Test");
       out.close();
       } catch (javax.naming.NamingException ne){
       ne.printStackTrace();
       PrintWriter out=res.getWriter();
       out.println("Test2");
       out.close();
       }
       }
      
       private static javax.naming.Context getInitialContext() {
       try {
       java.util.Properties environment = new java.util.Properties();
       environment.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
       environment.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
       environment.put(Context.PROVIDER_URL, "jnp://localhost:1099");
       return new javax.naming.InitialContext(environment);
       } catch(Exception e) {
       e.printStackTrace();
       return null;
       }
       }
      
      


      I try to find the Session-bean ArticleManager using a JNDI-lookup, but I always get the following error-message:

      22:22:12,359 ERROR [STDERR] javax.naming.NameNotFoundException: ArticleManager n
      ot bound
      


      However, when I have a look at the JNDI-view in the JBoss-server, I can see that my session-bean has been deployed:

      java:comp namespace of the component jboss.j2ee:service=EJB3,ear=texaco_deploy-1.0-SNAPSHOT.ear,jar=texaco_model-1.0-SNAPSHOT.jar,name=ArticleManager :
      
       +- UserTransaction (class: org.jboss.ejb3.tx.UserTransactionImpl)
       +- env (class: org.jnp.interfaces.NamingContext)
       | +- be.erpsystem.texaco.articles.ArticleManager (class: org.jnp.interfaces.NamingContext)
       | | +- em (class: org.jboss.ejb3.entity.TransactionScopedEntityManager)
      
      


      Finally, the code of my session-bean is as follows:

      @Stateless (mappedName="ArticleManager")
      public class ArticleManager implements ArticleManagerRemote, ArticleManagerLocal {
       @PersistenceContext (unitName="texaco") EntityManager em;
       public void testArticles(){
       int i=0;
       i*=2;
       }
      }
      


      As I'm very new to EJB / EJB 3.0, this might be an obvious question.

      Any help however, is very appreciated!

      Thanks
      Davy.

        • 1. Re: Stateless session bean not bound
          itsme

          hi,

          while I'm not tryed JBoss 5 yet as far as I read your JNDI-dump try it with the full class name of your bean or interface and leave out the /local

          Hope this helps.

          /sandor/

          • 2. Re: Stateless session bean not bound
            dgdwinte

            Thanks for your reply, but unfortunalety, the following change

            ArticleManagerLocal artman= (ArticleManagerLocal) ejbCtx.lookup("java:comp/env/be.erpsystem.texaco.articles.ArticleManager");
            


            doesn't work either :(

            Any other suggestions? Do you still need a deployment-descriptor in the web-tier? Or is there any need to inject the EJB?

            Thanks!
            Davy


            • 3. Re: Stateless session bean not bound
              itsme

              just another guess:

              'til jboss 4.2.0 - which we're using - the name of the jar is the root of the NamingContext. So adding the jar's name works for us without java:comp/env. While we're work with rmi calls, I don't have a glue if this java:comp/env stuff is needed.

              So I would give this a try:

              ejbCtx.lookup("texaco_model-1.0-SNAPSHOT.jar/be.erpsystem.texaco.articles.ArticleManager");
              


              /sandor/

              • 4. Re: Stateless session bean not bound
                waynebaylor

                you could also try just using the initialcontext

                Context jndiContext=getInitialContext();
                ArticleManagerLocal artman= (ArticleManagerLocal) jndiContext.lookup("ArticleManager/local");


                • 5. Re: Stateless session bean not bound
                  dgdwinte

                  Thanks for the replies. It still doesn't work, tried a dozen of jndi-lookup possibilities, but no success. However, injection works perfectly:

                  public class TestServlet extends HttpServlet {
                   private @EJB ArticleManagerLocal artman;
                   public void doGet(HttpServletRequest req, HttpServletResponse res)
                   throws ServletException, IOException{
                   artman.testArticles();
                   PrintWriter out=res.getWriter();
                   out.println("Hello, world said davy!");
                   out.close();
                  }
                  }
                  


                  As one is supposed to use injection in JBoss 5.0, I'll continue to use that.

                  Best regards,
                  Davy.