Success! After playing around with a few things, I got AOP working in Grails this weekend and I’ve checked in the changes to my example app. I’ve also added a test that more clearly shows aop in action.
I made a few changes inspired by Graeme’s comment on my earlier post on AOP in Grails. Graeme pointed me to BeanBuilderTests and both testSpringAOPSupport() and testUseSpringNamespaceAsMethod() were very helpful.
I also took a deeper look at the Spring docs on AOP – specifically around advice and advice params.
Looking at the changes I made, the first change clearly make some sense in retrospect. The second is a little confusing to me and I’m guessing that I’m doing something wrong.
- In my Aspects, I switched from using the aopalliance classes to aspectj classes. This meant instead of using org.aopalliance.intercept.MethodInvocation & MethodInterceptor classes, I used to org.aspectj.lang.ProceedingJoinPoint. That makes sense and I was just wrong before (not sure where I saw examples of this).
- The second set of changes I made were in the aop bean definition in resources.groovy.
- First, I needed to make sure that I was proxying the target class (
proxy-target-class=true). - Second, I had to define my execution point without explicit parameters. As in
Service.method(..)vs.Service.method(Integer) && args(i)(which I used with'arg-names':'i').
- First, I needed to make sure that I was proxying the target class (
The last changes are what confuse me. I tried a number of different things, but could not get explicit parameters to work. Apparently, I need read through the Spring docs on advice params again.
One new wrinkle is that when running the app, my around advice seems to be invoked twice. I wrote the test (inspired by BeanBuilderTests), but I don’t see the same problem when executing the test. Maybe it still has something to do with the pointcut execution declaration. My quest continues….

Pingback: refactr blog on software development, design, agile processes, and business Blog Archive » CircuitBreaker Pattern in Grails
Pingback: refactr blog on software development, design, agile processes, and business Blog Archive » Updates to Circuit Breaker Grails Plugin