title: How can I enable CDI with Jersey Test Framework?
body: <p>I found <a href="https://stackoverflow.com/q/5892349/330457">How can I inject a data source dependency into a RESTful web service with Jersey (Test Framework)?</a> but I think I'm gonna ask a little bit different question.</p>
  
  <p>This is a follow-up question of <a href="https://stackoverflow.com/q/29787068/330457">@PostConstruct of abstract ancestors are not invoked</a></p>
  
  <p>I wrote a JAX-RS library and I'm trying to unit-test with <a href="https://jersey.java.net/documentation/latest/test-framework.html" rel="nofollow noreferrer">Jersey Test Framework</a>.</p>
  
  <p>I seems HK2 injects properly. But I found some of my life cycle interceptor method annotated with <code>@PostConstruct</code> or <code>@PreDestroy</code> aren't invoked (or only some invoked).</p>
  
  <pre class="lang-java prettyprint-override"><code>public class MyResource {
  
      @PostConstruct
      private void constructed() { // not invoked
      }
  
      @Inject
      private Some some; // injection works.
  }
  </code></pre>
  
  <p>How can I enable CDI with Jersey Test Framework? What kind of artifacts do I have to depend on?</p>
  
  <p>Here is my current dependencies.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;dependency&gt;
    &lt;groupId&gt;javax.inject&lt;/groupId&gt;
    &lt;artifactId&gt;javax.inject&lt;/artifactId&gt;
    &lt;scope&gt;provided&lt;/scope&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;javax.ws.rs&lt;/groupId&gt;
    &lt;artifactId&gt;javax.ws.rs-api&lt;/artifactId&gt;
    &lt;scope&gt;provided&lt;/scope&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.glassfish.jersey.test-framework.providers&lt;/groupId&gt;
    &lt;artifactId&gt;jersey-test-framework-provider-grizzly2&lt;/artifactId&gt;
    &lt;scope&gt;test&lt;/scope&gt;
  &lt;/dependency&gt;
  </code></pre>