2017-06-26 96 views
1

我有一個JAXRS提供商:JavaEE的CDI和注入@Provider JAXRS給UnsatisfiedDependencyException

@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) 

我的其他豆類正在被發現和注入埠t @Provider中的這一項不起作用,我錯過了什麼?

+0

您正在使用哪臺服務器? – Rouliboy

+0

確保您使用的是javax.enterprise.context.RequestScoped而不是javax.faces.bean.RequestScoped – maress

+0

@Rouliboy我使用Glassfish 4.1作爲容器。 – Neilos

回答

1

從我的理解,問題是,我在beans.xml中有bean-discovery-mode="annotated",註釋JAX-RS類不會自動容器的CDI實施管理,因此有兩種可能的解決方案:

設置bean-discovery-mode="all"

OR

添加javax.enterprise.context.Dependent註釋AuthFilter篩選,讓CDI知道它是一個管理對象。