December 21, 2014

Java EE 6 Interceptors 1.0 (JSR318)


Interceptor was in EE 5 introduced in EJB 3.0, see EJB3 Interceptors javax.ejb.AroundInvoke. In EE 6 that was taken out and made generic into Interceptors (JSR318), package javax.interceptor.*.

You can call Interceptor in EE 6 in two way:

  • By annotating method or class with @javax.interceptor.Interceptors(MyInterceptor.class)
  • Create custom Annotation with Annotation @javax.interceptor.InterceptorBinding and annotate with that you method or class.


Your custom Interceptor.

Interception in a POJO.

Interception in a Stateless Session Bean.

beans.xml located for war in WEB-INF/.

To use the Interceptor you must let weld create the intercepted class, otherwise will weld never knew about the interceptor and hence will the interceptor never work.

Example usage from a Servlet.


You cannot use Interceptor directly in servlets, see

No comments: