Friday, July 9, 2004

AOP in J2EE, Tomcat tutorial

(imported from http://blogs.codehaus.org/people/avasseur, read comments there)

Since we released AspectWerkz 1.0 beta 1 some days ago, with a real cool feature we had in our roadmap since the very begining, I have written a small tutorial for you to practice.

AspectWerkz now supports the concept of an AOP container. No other AOP framework out there supports this idea in the way we do it : class loader aware and cross platform.
It is now possible to have an AOP deployment descriptor within your application, and interesting point in an AOP world: have several of them, all along your application.

The standard way of doing so is to use META-INF/aop.xml files, and for some container like Tomcat it is possible to use WEB-INF/aop.xml as well.
If you add a jar file in your application and this jar file contains a META-INF/aop.xml descriptor, it will also be taken into account. It is thus easy to distribute aspect jar file with predefined behavior.

You can drop Aspect classes at your system classpath and those will affect all deployed application, AND, you can have Aspect classes within your web application that will only affect this specific deployed application.

Read the tutorial here.


Note that if an Aspect is deployed within an application, the pointcut it defines will be limited by the class loader isolation principle. Even if the pointcut assumes to match all method in all classes, it will only "see" all methods in classes loaded by this classlaoder and the child classloader.

Try it now !