I think I'm asking this question but for Jersey 1.x: Dependency injection with Jersey 2.0
I'm using Glassfish 3, CDI and Jersey 1.x. I have a @WebService that is injecting a class like this:
@Inject
Foo foo;
I've tested this in the @WebService and it works. But the same line of code in my Jersey resource throws a NPE when it tries to use foo. I think Jersey 1.x is ignoring the CDI annotations. How can I get dependency injection working like it does in my @WebService?
Foo is a pojo and my web.xml is using the ServletContainer:
<servlet>
<servlet-name>JerseyServlet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
I've found some help here. The problem is my Foo @Injects its own beans (they're actually EJBs that come from a class with @Provides in it). resourceContext.getResource(Foo.class); returns an instance of Foo, but foo's @Injected fields are null.