简体   繁体   中英

CDI interceptor Scope annotation

Context:

Wildfly 8.1.0 with CDI 1.2

According to the CDI specification for CDI1.2 , you do not need to declare a cdi in beans.xml if it is annotated @Priority(somepriorityvalue)

However, the following cdi interceptors are never called unless I add the @Dependent annotation

@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();
  }
}

and the interceptor binding:

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

Note that the interceptor binding and interceptor are defined in a different jar module from where they are used (so the purpose for the @Priority).

Is it something I have overlooked? Why must I add the CDI 's @Dependent scope for the interceptor to kick?

Is it because I have specifically stated in the beans.xml bean-discovery-mode="annotated"

WildFly 8.1 ships with Weld 2.1.x (i forget x, but 2.1 is CDI 1.1 compliant). You can apply patches to it to upgrade to Weld 2.2 which is CDI 1.2 compliant and this issue should go away for you.

The behavior you're seeing is consistent with CDI 1.1 implementations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM