10 Replies Latest reply on Jul 18, 2012 9:07 PM by Kevin Hooke

    JAX-RS class on AS7 does not get EJB dependencies injected unless annotated as a SessionBean

    Kevin Hooke Newbie

      I have a JAX-RS class that takes an incoming POST and then calls a method on an injected EJB. Unless the JAX-RS class is annotated as a SessionBean itself, it appears the @EJB annotation is ignored and the dependency is never injected (the property is null).

       

      The EE6 tutorial implies that you need to annotate the JAX-RS class with @RequestScoped so that it can support CDI injections, but by itself this doesn't work on AS7

      http://docs.oracle.com/javaee/6/tutorial/doc/gkncy.html

       

      This approach does not work (queueService is null):

      @Path("queue")
      @RequestScoped
      public class QueueInputWS {
      
           @EJB
           private QueueMessageService queueService;
      ,...
      }
      

      But this does work (queueService gets set):

      @Path("queue")
      @Stateless
      public class QueueInputWS {
      
           @EJB
           private QueueMessageService queueService;
      ...
      }
      

       

      Thoughts? Is this a bug, or is it a requirement for JAX-RS classes to also be SessionBeans in order to use CDI?

       

      Thanks! Kevin