title: Jersey: How to inject EJB into sub resource?
body: <p>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.</p>
  
  <p>Some example code:</p>
  
  <ol>
  <li><p>A root resource</p>
  
  <pre><code>@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);
      }
  }
  </code></pre></li>
  <li><p>The corresponding sub resource</p>
  
  <pre><code>@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();
      }
  }
  </code></pre></li>
  </ol>
  
  <p>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 (<a href="https://stackoverflow.com/questions/21367855/best-way-to-expose-business-logic-to-restful-services-via-inject">here I'm pushing my other questions' view count to get more opinions ;-)</a>)!</p>
  
  <p>I tried everything I can think of but it just won't work...</p>
  
  <p>Currently I'm using the libraries that are shipped with glassfish 4.</p>
  
  <p>And of course, thank you in advance (almost forgot that)!</p>