我试着在HK2中使用泽西。我需要绑定非常奇怪的类型:
List<TransformationService<? extends Transformation, ? extends TransformationInfor>>
因此,我的活页夹定义如下:
resourceConfig.register(new AbstractBinder() {
@Override
protected void configure() {
List<TransformationService<? extends Transformation, ? extends TransformationInfo>> transformationServices = ... ;
bind(transformationServices)
.to(new TypeLiteral<List<TransformationService<? extends Transformation, ? extends TransformationInfo>>>() {});
// This class needs the list for its construction
bind(TransformationServiceImpl.class).to(TransformationService.class);
}
});但是,当我运行代码时,我得到了不能注入列表的异常(包已被发送):
[11/20/15 16:46:34] WARNING org.glassfish.jersey.internal.Errors logErrors : The following warnings have been detected: WARNING: Unknown HK2 failure detected:
MultiException stack 1 of 3
org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=List<TransformationService<? extends ...Transformation,? extends ...TransformationInfo>>,parent=TransformationServiceImpl,qualifiers={},position=3,optional=false,self=false,unqualified=null,334434299)
at org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:74)
at org.jvnet.hk2.internal.ClazzCreator.resolve(ClazzCreator.java:214)关于如何用HK2注射这种怪胎,有什么建议吗?
发布于 2015-11-22 12:06:37
据我所知,HK2注入规则对于CDI (见规范)是一样的。
在某些时候,它提到:
但是,有些Java类型不是合法bean类型:
我认为在我的示例中,我试图创建包含通配符的参数化类型的TypeLiteral。
无论如何,在我的例子中,我删除了那个无界类型,它可以工作。需要作出的改变是:
bind(transformationServices)
.to(new TypeLiteral<List<TransformationService>>() {});https://stackoverflow.com/questions/33830927
复制相似问题