Monday, January 24, 2005

Spring pointcut on steroids

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

Three months ago when we wrote the AWBench AOP benchmark suite, I had to hack some little Spring AOP aspect and pointcuts.

If you are familiar with Spring and know about AOP (AspectJ, AspectWerkz, JBoss etc), you know that Spring pointcuts are rather ... well sadly un-intuitives.
They might be for new users, but not anymore when you have very basic AOP knowlegde, and you are more and more !

I could not resist and integrating Spring with AspectWerkz pointcut (yes, once again for the third time, after the Spring container Jonas did and the extensible container we shipped.)

A Spring pointcut before the wedding with AspectWerkz - almost impossible to combine with other patterns unless you have your "Mastering Spring XML" in the pocket...

<bean id="theMethodExecutionGetTargetAndArgsAroundAdvisor1"
class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="advice">
<ref local="theMethodExecutionGetTargetAndArgsAroundAdvice"/>
</property>
<property name="pattern">
<value>.*aroundStackedWithArgAndTarget.*</value>
</property>
</bean>


Spring pointcut as a real pointcut thanks to the wedding with AspectWerkzPointcutAdvisor

<bean id="theMethodExecutionAfterThrowingAdvisor"
class="awbench.spring.AspectWerkzPointcutAdvisor">
<property name="advice">
<ref local="theMethodExecutionAfterThrowingAdvice"/>
</property>
<property name="expression">
<value>execution(* *..*.afterThrowingRTE(..))</value>
</property>
</bean>



Such a basic code source is there and should perhaps be reviewed by Spring guys for some of the API details.


The great news is that this will be part of a next release of Spring, and details will be handled by the AspectJ 5 engine instead. That was about time ;-)