6/5/08

Setting up EJB3 default interceptor

It wasn't easy to find out how to configure a default interceptor in EJB3 environment.
It's okay to make this snippet into the ejb-jar.xml:

<assembly-descriptor>
<interceptor-binding>
<ejb-name>*</ejb-name>
<interceptor-class>pkg.IC</interceptor-class>
</interceptor-binding>
</assembly-descriptor>

Maybe everybody forget to mention maybe it's a Glassfish V2 trick that I get this error message during deployment:

Interceptor binding contains an interceptor class name = pkg.IC that is not defined as an interceptor

...unless I register the interceptor class itself too with this:

<interceptors>
<interceptor>
<interceptor-class>pkg.IC</interceptor-class>
<around-invoke>
<method-name>call</method-name>
</around-invoke>
</interceptor>
</interceptors>

<interceptors> and <assembly-descriptor> are children of <ejb-jar> element in this order as it seems well in the xsd.