Topic
4 replies Latest Post - ‏2013-09-10T14:14:25Z by Gerhard Große
Gerhard Große
Gerhard Große
3 Posts
ACCEPTED ANSWER

Pinned topic @Inject and @EJB not working together in a servlet when deploying through WAS developer tools

‏2013-09-09T15:37:06Z |

I have an application with a servlet that uses @Inject to access a managed bean and @EJB to access an EJB:

@WebServlet("/test") public class CDITestServlet extends HttpServlet  {

    @Inject ApplicationBean applicationBean;
    @EJB StatelessEjb statelessEjb;

    protected void doGet(HttpServletRequest request, HttpServletResponse response)

      throws ServletException, IOException    {
        response.setContentType("text/plain");
        PrintWriter out = response.getWriter();
        out.println("applicationBean:  " + applicationBean);
        out.close();
    }
}

 

When I deploy this application with Eclipse and Websphere Developer Tools (8.5.5) the managed bean is not injected (reference is null). If I deploy the EAR through the WAS admin console the bean is injected alright.

This strange behavior goes away, when I remove the EJB reference (@EJB injection).

I have my beans.xml in the WebContent/WEB-INF folder. I tried putting it at alternative locations (classes/META-INF, WebContent/META-INF), but that did not work either.

Is this known? Is there a way to work around this behavior?

  • rsanchezh
    rsanchezh
    26 Posts
    ACCEPTED ANSWER

    Re: @Inject and @EJB not working together in a servlet when deploying through WAS developer tools

    ‏2013-09-09T15:57:33Z  in response to Gerhard Große

    Hello,

    This sounds similar to this: https://www.ibm.com/developerworks/community/forums/html/topic?id=1417e2c2-9b77-489d-a7d5-f2e7e720f266&ps=25.

    • Gerhard Große
      Gerhard Große
      3 Posts
      ACCEPTED ANSWER

      Re: @Inject and @EJB not working together in a servlet when deploying through WAS developer tools

      ‏2013-09-09T16:08:31Z  in response to rsanchezh

      Yes, this sounds very similar. But although this topic is marked as answered, I do not see what the solution should be. I also tried "Run server with resources on server" but that did not change the behavior.

      I'm using a fullprofile WAS 8.5 in developer mode, no liberty profile. And my bean (applicationBean) is not an EJB, so switching to @EJB instead of @Inject would not work.

  • ktsao
    ktsao
    3 Posts
    ACCEPTED ANSWER

    Re: @Inject and @EJB not working together in a servlet when deploying through WAS developer tools

    ‏2013-09-10T13:59:25Z  in response to Gerhard Große

    We're currently investigating the issue raised in https://www.ibm.com/developerworks/community/forums/html/topic?id=1417e2c2-9b77-489d-a7d5-f2e7e720f266&ps=25 .  In the meantime, the only workaround is to deploy using the WAS admin console.

    • Gerhard Große
      Gerhard Große
      3 Posts
      ACCEPTED ANSWER

      Re: @Inject and @EJB not working together in a servlet when deploying through WAS developer tools

      ‏2013-09-10T14:14:25Z  in response to ktsao

      Thanks for the info!