[[interceptors]]

== 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 an extent to which {cdi_lite} supports Jakarta Interceptors specification, including extending it with non-binding annotation values in interceptor resolution.

{cdi_lite} implementations are required to support following forms of interception:

* Interceptors declared on interceptor classes and associated with target class using interceptor binding annotations
** `@AroundInvoke`, `@PostConstruct`, `@PreDestroy` and `@AroundConstruct` are all supported
** Enablement and ordering of interceptors using `@Priority` annotation
* `@PostConstruct` and `@PreDestroy` declared on target class (i.e. on a bean)

Using other forms of interception results in non-portable behavior.

{cdi_full} implementations are required to support all forms of interception, as described in <<interceptors_full>>.

[[interceptor_bindings]]

=== Interceptor binding types

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

[[stereotype_interceptor_bindings]]

==== Interceptor bindings for stereotypes

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

[source, java]
----
@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_interceptor]]

=== 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_interceptor_to_bean]]

=== 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]]

=== Interceptor resolution

This specification extends the Jakarta Interceptors specification and defines the effect of applying `@Nonbinding` to an interceptor binding member.

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.
