I found How can I inject a data source dependency into a RESTful web service with Jersey (Test Framework)? but I think I'm gonna ask a little bit different question.
This is a follow-up question of @PostConstruct of abstract ancestors are not invoked
I wrote a JAX-RS library and I'm trying to unit-test with Jersey Test Framework.
I seems HK2 injects properly. But I found some of my life cycle interceptor method annotated with @PostConstruct
or @PreDestroy
aren't invoked (or only some invoked).
public class MyResource {
@PostConstruct
private void constructed() { // not invoked
}
@Inject
private Some some; // injection works.
}
How can I enable CDI with Jersey Test Framework? What kind of artifacts do I have to depend on?
Here is my current dependencies.
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-grizzly2</artifactId>
<scope>test</scope>
</dependency>
@BeforeClass
and@AfterClass
annotated methods to initialize and shutdown weld? Since this is a test class, it seems appropriate – Moeller