Hi!
Great framework and really nice guice integration! I'm having problems with
guice injection, it is injecting null. Actually I'm not 100% sure that the
resource is being instantiated by Guice.
I'm using jersey 1.1.1-ea-SNAPSHOT.
In my web.config I have:
<servlet>
<servlet-name>Troy</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.olx.troy.resources</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Troy</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>com.olx.troy.TroyGuiceConfig</listener-class>
</listener>
<filter>
<filter-name>Guice Filter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
The com.olx.troy.TroyGuiceConfig is:
public class TroyGuiceConfig extends GuiceServletContextListener {
@Override
protected Injector getInjector() {
return Guice.createInjector(new ServletModule() {
@Override
protected void configureServlets() {
bind(Something.class).to(SomethingImpl.class);
}
});
}
}
And my com.olx.troy.resources.CategoryResource is:
@Path("/category")
@Produces("application/json")
public class CategoryResource {
private Something something;
@Inject
public CategoryResource(Something something) {
super();
this.something = something;
}
@GET
public List<Category> listAll(@QueryParam(value = "country") int
countryId) {
List<Category> list = new ArrayList<Category>();
System.out.println(something.lala());
list.add(new Category(185, "For Sale"));
return list;
}
}
As you can see I want Guice to inject an instance of SomethingImpl.class to
CategoryResource constructor. But instead I'm getting a null.
I believe I'm missing something.
Thanks!
Jonathan
--
View this message in context: http://n2.nabble.com/Jersey-Guice-is-injecting-nulls-tp3031562p3031562.html
Sent from the Jersey mailing list archive at Nabble.com.