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 )