2 Replies Latest reply on Dec 15, 2012 1:52 AM by kolaye

    call ejb from war via JNDI problem

    kolaye

      Hi,

        I met a problem when I call ejb in a war.

        Firstly, I create a EJB project, and deploy it to JBoss AS7.1.1,it's successful

        code:

        1)UsersDao.java

      @Stateless

      @Remote(UsersDaoRemote.class)

      public class UsersDao implements UsersDaoRemote{

          @PersistenceContext //这里应用EJB3的IOC,得到EntityManager

          private EntityManager em; //相当于Hibernate的Session

          /**

           * Default constructor.

           */

          public UsersDao() {

              // TODO Auto-generated constructor stub

          }

       

          public String getForUsername(String username)

          {

           xxxx

          }

        2)UsersDaoRemote.java

      @Remote

      public interface UsersDaoRemote{

          public String getForUsername(String username);

      }

       

        secondly, I create a dynamic web project, and deploy it to JBossAs7.1.1 server successful

        code:

         public  void loginIn() throws NamingException
          {
               InitialContext  ctx = new InitialContext();

              //String ejbname = "ejb:sms_ejb/UsersDao!com.hxchn.sms.UsersDaoRemote";       

              String ejbname = "java:global/sms_ejb/UsersDao!com.hxchn.sms.UsersDaoRemote";       

       

              UsersDaoRemote usersDaoRemote=(UsersDaoRemote)ctx.lookup(ejbname);

        }

       

      but when the jsf call the loginIn function it failed, the log below

      root cause

      java.lang.RuntimeException: JBAS014487: Could not load view class for ejb UsersDao
           org.jboss.as.ejb3.remote.RemoteViewManagedReferenceFactory.getReference(RemoteViewManagedReferenceFactory.java:76)
           org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:133)
           org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:74)
           org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
           org.jboss.as.naming.InitialContext.lookup(InitialContext.java:123)
           org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214)
           javax.naming.InitialContext.lookup(InitialContext.java:392)
           com.hxchn.sms.UserJavaBean.loginIn(UserJavaBean.java:197)
           sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           java.lang.reflect.Method.invoke(Method.java:597)
           org.apache.el.parser.AstValue.invoke(AstValue.java:262)
           org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
           com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
           javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
           com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
           javax.faces.component.UICommand.broadcast(UICommand.java:315)
           javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
           javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
           com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
           com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
           com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
           javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
      

      root cause

      java.lang.ClassNotFoundException: com.hxchn.sms.UsersDaoRemote from [Module "deployment.sms_web.war:main" from Service Module Loader]
           org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
           org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
           org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
           org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423)
           org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
           org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
           java.lang.Class.forName0(Native Method)
           java.lang.Class.forName(Class.java:247)
           org.jboss.as.ejb3.remote.RemoteViewManagedReferenceFactory.getReference(RemoteViewManagedReferenceFactory.java:73)
           org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:133)
           org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:74)
           org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
           org.jboss.as.naming.InitialContext.lookup(InitialContext.java:123)
           org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214)
           javax.naming.InitialContext.lookup(InitialContext.java:392)
           com.hxchn.sms.UserJavaBean.loginIn(UserJavaBean.java:197)
           sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           java.lang.reflect.Method.invoke(Method.java:597)
           org.apache.el.parser.AstValue.invoke(AstValue.java:262)
           org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
           com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
           javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
           com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
           javax.faces.component.UICommand.broadcast(UICommand.java:315)
           javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
           javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
           com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
           com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
           com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
           javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) 
      ----------------------------------------------------------------------------------
      Can anyone help me?
        • 1. Re: call ejb from war via JNDI problem
          wdfink

          Looks like a classloading issue.

          You should have a look into the documentation here.

          If you have still questions you should attach the structure of your deployment

          • 2. Re: call ejb from war via JNDI problem
            kolaye

            Thanks Wolf-Dieter. I had resolved it lastnight.

            The method is copy the EJB interface class into the Web App's class path. and then the Web App can find the EJB class.

            And I also test the other method, I add the EJB remote interface (UsersDaoRemote.java) into the Web App's project, it work fine too!

            I had confused about the Web Container and the EJB container, since the Web Container have more and more functions about EJB(likes WebBean). Does it have possible that the Web Container replace the EJB Container, or the two Container combine to one Container in the future?