我有一个JAXRS提供商:
@Provider
@Priority(Priorities.AUTHENTICATION)
public class AuthFilter implements ContainerRequestFilter {
@Inject
private AuthSecurityContext authSecurityContext;
// ...
}
我的SecurityContext实现:
@RequestScoped
public class AuthSecurityContext implements SecurityContext {
// ...
}
我正在使用glassfish作为我的容器,但它抛出了以下异常:
2017-06-26T01:04:49.139+0100|Warning: The following warnings have been detected: WARNING: Unknown HK2 failure detected:
MultiException stack 1 of 1
org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=AuthSecurityContext,parent=AuthFilter,qualifiers={},position=-1,optional=false,self=false,unqualified=null,2049394753)
我的其他豆子被发现并被注射但是@Provider
中的这个豆子不起作用,我错过了什么?
答案 0 :(得分:2)
据我所知,问题是我在beans.xml中有bean-discovery-mode="annotated"
,JAX-RS注释类不会由容器的CDI实现自动管理,因此有两种可能的解决方案:
设置bean-discovery-mode="all"
OR
将javax.enterprise.context.Dependent
注释添加到AuthFilter,让CDI知道它是一个托管对象。