Skip to content

Latest commit

 

History

History
82 lines (51 loc) · 3.91 KB

interceptors.asciidoc

File metadata and controls

82 lines (51 loc) · 3.91 KB

Interceptor bindings

Managed beans support interception. Interceptors are used to separate cross-cutting concerns from business logic. The Jakarta Interceptors specification defines the basic programming model and semantics, and how to associate interceptors with target classes. This specification defines various extensions to the Java Interceptors specification, including non-binding annotation values in interceptor resolution.

{cdi_lite} implementations are not required to support associating interceptors with classes and methods using the @jakarta.interceptor.Interceptors annotation. They are required to support interceptor binding annotations.

Interceptor binding types

This specification extends the Jakarta Interceptors specification and allows interceptor bindings to be applied to CDI stereotypes.

Interceptor bindings for stereotypes

Interceptor bindings may be applied to a stereotype by annotating the stereotype annotation:

@Transactional
@Secure
@RequestScoped
@Stereotype
@Target(TYPE)
@Retention(RUNTIME)
public @interface Action {}

An interceptor binding declared by a stereotype is inherited by any bean that declares that stereotype.

If a stereotype declares interceptor bindings, it must be defined as @Target(TYPE).

Declaring the interceptor bindings of an interceptor

This specification extends the Jakarta Interceptors specification and defines how the container must behave if a definition error is encountered.

If an interceptor declares any scope other than @Dependent, the container automatically detects the problem and treats it as a definition error.

Binding an interceptor to a bean

This specification extends the Jakarta Interceptors specification and defines:

  • additional restrictions about the type of bean to which an interceptor can be bound, and

  • how the container must behave if a definition error is encountered, and

  • how interceptors are bound using stereotypes.

Interceptor bindings may be used to associate interceptors with any managed bean.

The set of interceptor bindings for a method declared at class level includes those declared on stereotypes. An interceptor binding declared on a bean class replaces an interceptor binding of the same type declared by a stereotype that is applied to the bean class.

The set of interceptor bindings for a producer method is not used to associate interceptors with the return value of the producer method.

If a managed bean has a class-level or method-level interceptor binding, the managed bean must be a proxyable bean type, as defined in [unproxyable].

Interceptor resolution

This specification extends the Jakarta Interceptors specification and defines:

  • the effect of applying @Nonbinding to an interceptor binding member, and

  • how the interceptor bindings of a custom implementation of the Interceptor interface are determined.

If any interceptor binding has a member annotated @jakarta.enterprise.util.Nonbinding, the member is ignored when performing interceptor resolution, and the method does not need to have the same annotation member value.

For a custom implementation of the Interceptor interface defined in [interceptor], the container calls getInterceptorBindings() to determine the interceptor bindings of the interceptor and intercepts() to determine if the interceptor intercepts a given kind of lifecycle callback or business method.

A custom implementation of the Interceptor interface may implement the Prioritized interface to be enabled for the entire application with a priority value.