2 Replies Latest reply on May 12, 2007 10:55 PM by xubin

    EJB3 and jndi error.

    xubin

      I have a project on JBoss AS 4.0.5.GA with EJB3, the jdk is sun jdk6. And there is a stateless session bean(slsb) in my project. Another servelt in tomcat access the slsb with jndi. The error is that I can not find the slbs by jndi.
      Below is the code:

      slsb:

      package com.sacl.ibs.ejb3;
      
      import java.io.Serializable;
      import java.util.List;
      
      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      
      import org.jboss.annotation.ejb.RemoteBinding;
      import org.jboss.annotation.ejb.RemoteBindings;
      
      @Stateless
      @RemoteBindings(@RemoteBinding(jndiBinding="com.sacl.ibs.ejb3.IBSManager"))
      public class IBSManagerBean implements IBSManager, Serializable {
       private static final long serialVersionUID = -2836261119947098786L;
       @PersistenceContext(unitName="ibs")
       EntityManager em;
      
      }












      servlet:

      package com.sacl.ibs.web;
      
      import java.io.IOException;
      import java.io.PrintWriter;
      import java.util.Properties;
      
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      import javax.servlet.ServletConfig;
      import javax.servlet.ServletException;
      import javax.servlet.http.HttpServlet;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      
      import com.sacl.ibs.ejb3.IBSManager;
      
      public class JNDIServlet extends HttpServlet{
      
       private static final long serialVersionUID = 3636864192783338015L;
       private static Context ctx;
       private static IBSManager manager;
      
       public void init(ServletConfig config) throws ServletException {
      
       }
      
      
      
       protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doPost(req, resp);
       }
      
       protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       try {
       PrintWriter out = resp.getWriter();
      
       if(ctx == null){
       Properties env = new Properties();
       env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
       env.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interface");
       env.setProperty(Context.PROVIDER_URL, "jnp://localhost:1099");
      
       out.println("env ok!");
      
       try {
       ctx = new InitialContext(env);
       if(manager == null){
       //manager = (IBSManager)ctx.lookup(IBSManager.class.getName());
       manager = (IBSManager)ctx.lookup("java:"+IBSManager.class.getName());
       out.println("manager ok!");
      
       //ctx.lookup("java:comp/env/ejb/com/atsva/cmmts/ejb/DesignObjectManager");
      
       }
      
       } catch (NamingException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
       out.println(e);
       }
       }
      
      
      
      
       out.println(manager.hello("Kitty"));
      
       } catch (Exception e) {
       // TODO: handle exception
       }
      
      
       }
      
      
      }




      When I run the servlet, it show "javax.naming.NameNotFoundException: com.sacl.ibs.ejb3.IBSManager not bound".

      And in jboss as console, when jboss as start, it show:
      13:49:51,609 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
      13:49:51,609 INFO [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
      13:49:51,843 INFO [EJBContainer] STARTED EJB: com.sacl.ibs.ejb3.IBSManagerBean ejbName: IBSManagerBean
      13:49:51,906 INFO [EJB3Deployer] Deployed: file:/C:/jboss-4.0.5.GA/server/default/tmp/deploy/tmp33327IBS.ear-contents/IBS.par
      13:49:51,953 INFO [EARDeployer] Started J2EE application: file:/C:/jboss-4.0.5.GA/server/default/deploy/IBS.ear

      It don't say the session bean was been bound.

      I'll appreciate any help with this.

      Thanks







        • 1. Re: EJB3 and jndi error.
          oskar.carlstedt

          Hi!

          Take a look in the jmx console/jndi view to see under what name you ejb is bound. For me it looks like you forgot a slash right after the "java:".

          With kind regards
          Oskar

          • 2. Re: EJB3 and jndi error.
            xubin

            Thank Oskar.

            I have look the jmx console/jndi , no found anything about my slsb.

            I think maybe the slsb no been bound to the jndi at all. But I don't know what's mistake.