The @Interceptors annotation (jakarta.interceptor.Interceptors, formerly javax.interceptor.Interceptors) attaches one or more interceptor classes to a managed bean, an EJB, or to individual methods of one. The container then runs the interceptor's code around each business method call, so cross-cutting concerns such as logging, auditing, security checks and timing stay out of your business logic.
It is part of the Jakarta Interceptors specification, used by Jakarta EE (EJB and CDI beans) and by runtimes such as WildFly, Payara, Open Liberty and Quarkus. It is not used in Spring, which has its own AOP support.
@Interceptors takes an array of interceptor classes. Each class contains an interception method annotated with @AroundInvoke that receives an InvocationContext. When a client calls a method of the intercepted bean, the container calls the interceptor first. The interceptor decides whether to continue by calling ctx.proceed(), and it can inspect or change parameters and the return value, or throw its own exception.
The annotation can be placed on:
Since the interceptor runs in the same transaction and security context as the bean method (unless you configure otherwise), it can see exactly what the business method sees.
An interceptor is a plain class with a public no-argument constructor and one interception method.
Apply it to an EJB or CDI bean:
Every call to placeOrder now goes through TimingInterceptor.measure. Moving the annotation onto the method limits the effect to that one method.
The InvocationContext gives you the target object (getTarget()), the Method being called, the parameters (getParameters() and setParameters()), a context data map shared by all interceptors in the chain, and proceed().
Besides @AroundInvoke, an interceptor class can declare other kinds of interception methods:
| Annotation | Runs around |
|---|---|
@AroundInvoke | business method calls |
@AroundConstruct | constructor of the target bean |
@PostConstruct | after dependency injection, before the bean is used |
@PreDestroy | before the container destroys the bean |
@AroundTimeout | EJB timer callbacks |
Lifecycle interceptors do not return a value and receive the same InvocationContext. Only call proceed() when you want the chain to continue.
When several interceptors apply to a call, the container runs them in a fixed order:
ejb-jar.xml, applying to every bean in the module);@Interceptors;The order inside the annotation is the execution order:
Here SecurityInterceptor runs before AuditInterceptor. You can opt out for a specific method:
@ExcludeClassInterceptors skips the class-level interceptors for that method, and @ExcludeDefaultInterceptors skips the default ones.
@Interceptors names the interceptor class directly, so the bean is tightly coupled to it and the ordering is scattered over many classes. The CDI-style alternative is an interceptor binding: you define your own annotation, mark the interceptor with it, and annotate beans with the binding.
Then write @Audited on any bean or method. The @Priority value both enables the interceptor for the whole application and defines its place in the chain (lower numbers run first). Interceptors declared with @Interceptors need no such enabling step.
@Interceptors | Interceptor binding | |
|---|---|---|
| Coupling | bean names the interceptor class | bean names a binding annotation |
| Ordering | position in the annotation | @Priority on the interceptor |
| Enabling | not needed | @Priority or beans.xml |
| Reuse across modules | harder | easier |
Use @Interceptors for a quick, local interception on an EJB. Use bindings when the same concern applies to many beans.
The javax.interceptor package belongs to Java EE 8 and earlier. From Jakarta EE 9 onwards the same API lives in jakarta.interceptor, so you only change the import. The behaviour is the same.
Yes. The @AroundInvoke method returns an Object, which becomes the result the caller sees. You can return the value from proceed() unchanged, modify it, or return something else entirely.
No. Interception is applied by the container through a proxy or subclass, so it works for business methods called through the container reference. Calls from one method of the bean to another on this bypass the interceptors.
No. Spring does not implement Jakarta Interceptors. Use Spring AOP with @Aspect and @Around advice instead.
@Interceptors wires interceptor classes into the call path of a Jakarta EE bean or method so cross-cutting behaviour lives in one place. Interceptors implement @AroundInvoke (and optionally lifecycle callbacks), receive an InvocationContext, and decide when to call proceed(). Execution order is default, class, then method level, in the order listed. For larger applications, prefer interceptor bindings with @Priority, and remember that the API moved from javax.interceptor to jakarta.interceptor.