36.9. Interceptors
In the Java EE 6, the concept of interceptors was extracted into a separate specification. As a result, not only EJBs but any CDI managed beans can benefit from this facility.
If you used interceptors in Seam 2, migration is straightforward. The names and semantics of most of the annotations remain unchanged. If you used meta-annotations to bind interceptors to your beans in Seam 2, this idea (slightly modified) made it into the specification and is now know as an Interceptor binding.
In addition to interceptors, CDI defines the concept of a Decorator. This concept is superficially similar to interceptors, but because decorators directly implement operations with business semantics they are able to implement business logic and, conversely, unable to implement the cross-cutting concerns for which interceptors are optimized.
Note that:
- It is not possible to declare relative ordering of interceptors anymore, that is whether my interceptor should be invoked before or after another interceptor. Interceptors must be globally activated and ordered in the
beans.xmlfile. - The performance optimization used by Seam 2 for stateless interceptors is not supported in CDI. Interceptors always share the life cycle with the bean they intercept.