Java Reference
In-Depth Information
StudentSessionBeanWithoutInterceptor {
//Method to intercept
}
By default, the interceptor is not enabled. To do this, you must declare the interceptor
in the bean.xml file as follows:
<interceptors>
<class>com.packt.ch08.bean.LoggerInterceptor</class>
</interceptors>
Defining the execution order of interceptors
When we talked about the CDI Specification in the Chapter 7 , Annotations and CDI ,
we discussed adding the @Priority annotation. This annotation was adopted by
the Interceptors 1.2 Specification and permits us to define an execution order for in-
terceptors that were declared with interceptor bindings. When using this annotation,
the interceptor with the smallest priority is called first. The following code demon-
strates how to use this annotation. In our case, the LoggerInterceptor intercept-
or will be called before the LoggerInterceptor1 interceptor.
@Log
@Interceptor
@Priority(2000)
public class LoggerInterceptor {
// interceptor method
}
@Log1
@Interceptor
@Priority(2050)
public class LoggerInterceptor1 {
//Interceptor method
}
Search WWH ::




Custom Search