Advanced interceptors

These next sections will delve deeper into interceptor binding types to explain more advanced use cases of them. We will cover binding types with members, how to combine different interceptors for a single use, and how binding types can be inherited.

Interceptor binding types with members

Just as with qualifier annotations, we can also add members to interceptor binding types too, such as:

@InterceptorBinding
@Target( { METHOD, TYPE } )
@Retention( RUNTIME )
public @interface Audited {
  boolean logToFile() default false;
}

With the binding type we just created, we need to create a new interceptor that matches the situation of logToFile being true, as CDI uses the member as a means for choosing a different interceptor implementation. ...

Get JBoss Weld CDI for Java Platform now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.