I am using jersey to inject POJOs on various locations. Here is my config:
register(new AbstractBinder() {
@Override
protected void configure() {
bind(Bar.class).to(Bar.class).in(Singleton.class);
bindFactory(FooFactory.class).to(Foo.class).in(Singleton.class);
...
}
});
FooFactory:
public class FooFactory implements Factory<Foo> {
@Override
public Foo provide() {
return Foo.newInstance();
}
}
Injecting into a resource works:
@Path("/myresource")
public class MyResource{
@Inject
protected Bar instance;
}
But
public class Foo {
@Inject
protected Bar instance;
}
does not. Foo.instance
is null. Why? And how to make it work?