我正在启动一个平针织服务器,并在其上注册过滤器。
public static HttpServer startServer() {
// create a resource config that scans for JAX-RS resources and providers
// in com.example package
final ResourceConfig rc = new ResourceConfig()
.packages("com.resource_packages")
.register(JacksonFeature.class)
.register(
new AbstractBinder() {
@Override
protected void configure() {
bindFactory(new FooFactory()).to(Foo.class).in(Singleton.class);
}
})
.register(ContainerRequestFilter.class)
.register(ContainerResponseFilter.class);
// create and start a new instance of grizzly http server
// exposing the Jersey application at BASE_URI
return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
}
在我的过滤器类中,我正在尝试使用javax.Inject注入一个对象
class ContainerRequestFilter {
@Inject
Foo foo;
}
class Foo {
private A objectA;
private B objectB;
Foo(A objectA, B objectB) {
this.objectA = objectA;
this.objectB = objectB;
}
}
据我所知泽西岛使用hk2进行依赖注入,那么我怎样才能让Jersey的hk2依赖注入意识到我的非资源或特定于球衣的类?