我正在像这样向HK2注入布尔值:
binder.bind(disableMyFeature).named("disableMyFeature").to(Boolean.class)
然后我尝试像这样注入它:
@Named("disableMyFeature") final boolean disableMyFeature
但是我有这个例外:
A MultiException has 3 exceptions. They are:
1. org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=boolean,parent=MyService,qualifiers={@javax.inject.Named(value="disableMyFeature")},position=11,optional=false,self=false,unqualified=null,381397683)
2. java.lang.IllegalArgumentException: While attempting to resolve the dependencies of my.package.MyService errors were found
3. java.lang.IllegalStateException: Unable to perform operation: resolve on my.package.MyService
如果我将此行的类别更改为Boolean
,则注入将起作用:
@Named("disableMyFeature") final Boolean disableMyFeature
这很奇怪,因为我可以混合使用Integer
和int
,或者Double
和double
和HK2可以毫无问题地注入它们。
HK2甚至可以注入:
binder.bind(disableMyFeature).named("disableMyFeature").to(boolean.class)
对此:
@Named("disableMyFeature") final Boolean disableMyFeature
因此,如果HK2可以从Boolean -> boolean
和其他装箱类注入到基元,为什么从boolean -> Boolean
注入会有问题?