Uploaded image for project: 'JBoss Enterprise Application Platform'
  1. JBoss Enterprise Application Platform
  2. JBEAP-110

NPE when @Inject @Stateless service in a JAX-RS class

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Do
    • Major
    • None
    • 6.2.0.GA
    • REST
    • None
    • Workaround Exists
    • Hide

      Annotate the JAX-RS class with @Stateless.

      Show
      Annotate the JAX-RS class with @Stateless .

    Description

      I've got that JAX-RS webservice:

          @Path("/my")
          public class MyWS {
      
              @Inject
              private MyService myService;
      
              @POST
              @Path("/save")
              @Consumes("application/json")
              public void save(SaveParam saveParam) {
                  myService.save(saveParam);
              }
          }
      

      and that @Stateless service:

          @Stateless
          public class MyService {
      
              @PersistenceContext
              protected EntityManager entityManager;
      
              @TransactionAttribute
              public void save(SaveParam saveParam) {
                  entityManager.persist(saveParam);
              }
          }
      

      Using JBoss EAP 6.2, myService is always null (not injected) when arriving in the save method.

      I've tried to add @ApplicationScoped to MyWS class, but the same behavior is happening (NullPointerException). The only solution is to declare MyWS also as @Stateless, but that should be mandatory.

      All my classes are in the same war project and I have a WEB-INF/beans.xml using CDI 1.0 spec. I also have a class extending javax.ws.rs.core.Application and declaring the @ApplicationPath.

      (Original post on Stackoverflow )

      Attachments

        Activity

          People

            rhn-cservice-bbaranow Bartosz Baranowski
            aogier_jira Anthony O. (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: