This chapter will cover how interceptors and decorators can be utilized within our CDI applications, while doing so in a typesafe manner through annotations. We will examine how interceptor bindings are created through annotations and then how to create and enable an interceptor. In decorators, we talk about what a delegate is before enabling decorators in a manner similar to interceptors.
Interceptors and decorators behave as two different sides of the same coin. Interceptors are perfect for separating concerns that are orthogonal to our application purpose by cutting across all layers of our application to perform an identical task. These tasks usually relate to technical matters such as transaction management, security, and method logging.
As interceptors are not aware of the semantics of what they intercept, they are not suited for separating business concerns, but that's where decorators come into play. As decorators intercept methods on a specific...