6 Replies Latest reply on Dec 8, 2011 12:02 PM by iran zhou

    Use remote EJB from Servlet + DI: doesn't work

    kan ff Newbie

      Hello,

      I've created two projects in Eclipse: one for a simple EJB. I've successfully deployed it in the JBoss (standalone deployment folder) and it works fine.

       

      EJB Interface:

      {code:java}

      package kf;

      import javax.ejb.Remote;

       

      @Remote

      public interface SessionBeanTryRemote {

                String getResult();

                String getAddress();

                String getCompanyname();

      }

      {code}

       

       

      EJB bean:

       

      {code:java}

      package kf;

      import javax.ejb.Stateless;

       

       

      @Stateless (name="sessionBeanT")

      public class SessionBeanTry implements SessionBeanTryRemote {

       

          public String getResult() {

                          return "Hello World";

                }

                public String getAddress() {

                          return "moon";

                }

                public String getCompanyname() {

                          return "company";

                }

      }

       

      {code}

       

      From Eclipse, I've created an EJB JAR and deployed it. JBoss log messages show the following after deployment:

       

      {quote}

      16:10:58,215 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-2) JNDI bindings for session bean name

      d sessionBeanT in deployment unit deployment "ejb_try.jar" are as follows:

       

       

              java:global/ejb_try/sessionBeanT!kf.SessionBeanTryRemote

              java:app/ejb_try/sessionBeanT!kf.SessionBeanTryRemote

              java:module/sessionBeanT!kf.SessionBeanTryRemote

              java:global/ejb_try/sessionBeanT

              java:app/ejb_try/sessionBeanT

              java:module/sessionBeanT

       

      {quote}

       

      My second project is a "Dynamic Web Project" in Eclipse and contains primarily a servlet now:

       

      {code:java}

      import java.io.IOException;

      import java.io.PrintWriter;

      import javax.ejb.EJB;

      import javax.servlet.ServletException;

      import javax.servlet.annotation.WebServlet;

      import javax.servlet.http.HttpServlet;

      import javax.servlet.http.HttpServletRequest;

      import javax.servlet.http.HttpServletResponse;

      import kf.SessionBeanTryRemote;

       

       

      @WebServlet("/servletA")

      public class servletA extends HttpServlet {

                @EJB (name="sessionBeanT")

                private SessionBeanTryRemote beanRef;

       

       

                private static final long serialVersionUID = 1L;

                protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

                          PrintWriter out = response.getWriter();

                          out.println(beanRef.getResult());

                }

                protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

                }

      }

      {code}

       

      I deploy this project as a WAR file into the same deployment folder. But looks like JBoss can't resolve the EJB name

       

      16:27:25,220 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) Starting deployment of "servletJboss.war"

      16:27:25,314 INFO  [org.jboss.as.jpa] (MSC service thread 1-4) added javax.persistence.api dependency to servletJboss.war

      16:27:25,360 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC00001: Failed to start service jboss.deployment.unit."servletJboss.war".INSTALL: org

      .jboss.msc.service.StartException in service jboss.deployment.unit."servletJboss.war".INSTALL: Failed to process phase INSTALL of deployment "servletJboss.war"

              at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:121)

              at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)

              at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)

              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [:1.7.0]

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [:1.7.0]

              at java.lang.Thread.run(Thread.java:722) [:1.7.0]

      Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: No component found for type 'kf.SessionBeanTryRemote' with name null

       

      My WAR file structure:

      META-INF/MANIFEST.MF

      META-INF/

      WEB-INF/

      WEB-INF/classes/

      /WEB-INF/classes/kf/

      WEB-INF/classes/kf/SessionBeanTryRemote.class

      WEB-INF/classes/servletA.class

      WEB-INF/lib/

       

       

       

       

      Can't figure it out why JBoss can't find the EJB. Please help.

       

      Oh, and I'm using "jboss-as-web-7.0.1.Final" version.

       

      Regards,

      Kan