1 Reply Latest reply on Sep 13, 2008 2:11 AM by jaikiran pai

    Is annotation enough for deploying a session bean?

    Dan Man Newbie

      Hi,

      I am using jboss-4.2.3.GA with Java 5. I have created a session bean like this:

      @Stateless
      @Local( { MyBeanInterface.class })
      public class MyBean implements MyBeanLocal, MyBeanInterface {
       ...
      
      }
      

      Also created a servlet like this:

      public class MyServlet extends HttpServlet {
       private static final long serialVersionUID = 1L;
      
       @EJB
       private MyBean myBean;
      
       public void service(HttpServletRequest request,
       HttpServletResponse response) throws ServletException, IOException {
       System.out.println("the servlet MyServlet has been invoked");
       if (myBean == null) {
       System.out.println("myBean is NULL");
       } else {
       System.out.println("myBean is not NULL");
       }
       ...
       }
      
       ...
      
      }
      

      I put everything in an ear file and deployed it in the server. When I try to invoke the servlet it complains that the bean has not been properly injected into the servlet. Here is the log on the server:

      14:38:02,568 INFO [EARDeployer] Init J2EE application: file:/C:/jboss-4.2.3.GA/server/jms/deploy/myEnterpriseProject.ear
      14:38:04,928 INFO [JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.stateless.StatelessContainer
      14:38:04,936 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:ear=myEnterpriseProject.ear,jar=myEjbProject.jar,name=MyBean,
      service=EJB3 with dependencies:
      14:38:04,959 INFO [EJBContainer] STARTED EJB: myPackage.MyBean ejbName: MyBean
      14:38:10,958 INFO [EJB3Deployer] Deployed: file:/C:/jboss-4.2.3.GA/server/jms/tmp/deploy/tmp38195myEnterpriseProject.ear-contents/m
      yEjbProject.jar
      14:38:11,067 INFO [TomcatDeployer] deploy, ctxPath=/abc, warUrl=.../tmp/deploy/tmp38195myEnterpriseProject.ear-contents/myDynamicWe
      bProject-exp.war/
      14:38:13,172 INFO [EARDeployer] Started J2EE application: file:/C:/jboss-4.2.3.GA/server/jms/deploy/myEnterpriseProject.ear
      14:38:23,255 INFO [STDOUT] myBean is NULL
      14:38:23,257 ERROR [[MyServlet]] Servlet.service() for servlet MyServlet threw exception
      java.lang.NullPointerException
      at myServletPackage.MyServlet.service(MyServlet.java:115)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
      at java.lang.Thread.run(Thread.java:619)

      I can see MyBean starting but it is not in the servlet. Do I still need to create the deployment ejb-jar.xml file for the jar file containing the bean? I thought the annotation would do the job for the trivial case.
      I would appreciate any suggestion.
      Thanks.

      Dan