上下文:
Wildfly 8.1.0与CDI 1.2
根据CDI CDI1.2规范,如果cdi是带注释的@Priority(somepriorityvalue),则不需要在beans.xml中声明
但是,除非我添加了@Dependent注释,否则永远不会调用以下cdi拦截器
@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 {
}请注意,拦截器绑定和拦截器是在与使用它们的地方不同的jar模块中定义的(这就是@优先级的目的)。
是不是我忽略了什么?为什么我必须添加CDI的@Dependent作用域才能启动拦截器?
是因为我在“beans.xml bean-discovery-mode="annotated"”中特别声明了
发布于 2015-04-23 00:37:51
WildFly 8.1附带了Weld 2.1.x (我忘记了x,但2.1兼容CDI1.1)。您可以将补丁应用到它,以升级到符合CDI1.2的Weld 2.2,这个问题应该可以为您解决。
您所看到的行为与CDI1.1实现是一致的。
https://stackoverflow.com/questions/29805876
复制相似问题