+

Search Tips   |   Advanced Search

EJB 3.0 interceptors


An interceptor is a method that is automatically called when the business methods of a bean are invoked.

We can define interceptors for session or message-driven beans. Business method interceptors can be defined to apply to all business methods of a bean class or to specific business methods only.

You denote interceptor classes using the Interceptor annotation on the bean class, or in the deployment descriptor using the <interceptor> element. Interceptor methods are marked with the AroundInvoke annotation or with the <around-invoke> element of the deployment descriptor. The interceptor methods always follow the pattern Object <method_name> (InvocationContext c) throws Exception.

Interceptors that apply to all session and message-driven beans in an ejb-jar file, known as default interceptors, are defined in the deployment descriptor using the <interceptor-binding> element. Interceptor methods can also be applied to specific methods rather than default to all methods or to specific beans by using the Interceptors annotation.

We can define any number of interceptors for a bean class. They are invoked in the order that they are specified. Interceptors defined in external classes are processed before interceptors defined within a bean class.



Related concepts


Enterprise beans

 

Related tasks


Develop enterprise beans

 

Related


Enterprise bean development best practices