2015-04-22 137 views
4

语境:CDI拦截范围注释

Wildfly 8.1.0CDI 1.2

按照CDI规范CDI1.2,你不需要在beans.xml申报CDI如果注释@Priority(somepriorityvalue)

然而,除非我添加@Dependent注释

@RequiresLoggedInAccount 
@Interceptor 
@Priority(Interceptor.Priority.APPLICATION) 
public class MyInterceptor { 

    @AroundInvoke 
    public Object intercept(final InvocationContext ic) throws Exception { 
    //intercept something and then... 
    return ic.proceed(); 
    } 
} 

和拦截器绑定:

@Inherited 
@Documented 
@InterceptorBinding 
@Target({METHOD, TYPE}) 
@Retention(RUNTIME) 
public @interface RequiresLoggedInAccount { 
} 

注意,拦截器绑定和拦截器被不同的罐模块中从所使用的地方它们定义(因此的宗旨,为@priority)。

这是我忽略的东西吗?为什么我必须添加CDI@Dependent范围拦截器踢?

难道是因为我在beans.xmlbean-discovery-mode="annotated"

+0

WildFly 8.1附带焊接2.1。您是否手动升级到Weld 2.2? –

+0

@JohnAment哦,该死的。它确实附带了CDI 1.1,这是否解释了这种行为? – maress

+0

这是否也可以解释为什么使用两个不同的InterceptorBindings注释单个拦截器会导致拦截器无法加载? – maress

回答

0

WildFly 8.1附带焊接2.1.x的特别声明(我忘了X,但2.1 CDI 1.1兼容)。您可以将补丁应用到它以升级到符合CDI 1.2的Weld 2.2,并且此问题应该会消失。

您看到的行为与CDI 1.1实现一致。