I would like to inject a buisiness service bean in a sub resource which is defined in a dedicated class and delivered by a sub resource locator.
Some example code:
A root resource
@RequestScoped @Path("service") public class MyResource { @Context ResourceContext resourceContext; // Sub resource locator @Path("subservice") public MySubResource locateToSubResource () { // I don't want to create it myself. return resourceContext.getResource(MySubResource.class); } }
The corresponding sub resource
@RequestScoped public class MySubResource { // Note that businessBean itself consists of // multiple ejbs that also need to be injected so that it can do its job! @Inject private BusinessBean businessBean; @GET @Produces(MediaType.TEXT_PLAIN) public String get () { return businessBean.doStuff(); } }
Jersey won't CDI let invoke the dependencies... Note that the resources are managed objects. Otherwise it wouldn't even be possible to inject a bean in a root resource (here I'm pushing my other questions' view count to get more opinions ;-))!
I tried everything I can think of but it just won't work...
Currently I'm using the libraries that are shipped with glassfish 4.
And of course, thank you in advance (almost forgot that)!