6 Replies Latest reply on Mar 11, 2009 5:00 AM by Andreas Bauer

    EJB reference in Servlet always null

    Andreas Bauer Newbie

      Hi,


      I use JBoss 4.2.2 on Mac OS with JDK 1.5.

      First, I created a Session:

      @Stateful(name="ViewerBean")
      public class ViewerBean implements Viewer,
       ViewerLocal{
      


      Then I want to call the bean from a servlet:

      public class ViewerServlet extends HttpServlet {
      
       //inject EJB
       @EJB(mappedName="ViewerBean")
       private ViewerBean bean;
      
       private static final long serialVersionUID = 1L;
      
      
       /**
       * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
       */
       protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       try {
       List events = bean.getEvents();
      ...
      


      I haven't added anything to the ejb-jar.xml as the annotations should be sufficient. But everytime I want to call bean.getEvents() I get a NullPointerException.

      I have an EJB3 project created in eclipse, as well as an EAR project. Both are deployed on the same server and the EAR client program references the EJB3 project, so I can use the ViewerBean in the client.

      Is this correct? Could you give me any hints on what I'm actually missing?

      Best regards,

      Andreas