I'm enjoying another year of presenting at the Colorado Software Summit. One of my talks is about AOP with Spring 2.0, covering both the use of Spring AOP and of AspectJ within Spring. I've really enjoyed some of the dialog with attendees when I give this talk and afterwards: it's great to hear how people are making real use of AOP and new ideas for additional uses.
At one bank, they are using Spring AOP with Spring MVC to scan incoming Web requests for SQL injection attacks. In another department they are using AspectJ to implement use cases separately such as sending email notifcations after business events, supporting state-specific regulations in a Web application, handling encrypted fields and white space trimming on Web requests. Another group is looking to detect resource failures and short-circuit requests that would use them to avoid tying up threads (while checking for restored availability periodically). This is an interesting scenario for integrating with Glassbox to detect the outages, with custom logic to manage requests when there are outages.
Another interesting use case I heard about is audting data when committing transactions using Spring AOP. It turns out you can use the Spring ordered interface to ensure the audit logic can set up just before the transaction commits (so it can be included in the transaction!). However I don't see how you specify the order of the transaction aspect in @AspectJ aspects in the relevant Spring docs as of today (Oct. 25): it is shown in the XML schema-defined .
In my talk I also give an example of how to use Spring AOP to proxy persistent objects after a DAO returns them by executing advice after they are returned, say by a finder method in a DAO. Now this isn't as nice as using AspectJ to configure and otherwise advise these objects, but it can be a useful approach for those using Spring AOP but not yet AspectJ. This code uses the ability to explicitly create @AspectJ proxies in Spring AOP code, which is also fine.
It's been interesting working a bit with @AspectJ with Spring: you can get good tools support by turning on AJDT while being ableto preserve very natural incremental development in Eclipse. I'm still continuing to use traditional AspectJ syntax for my projects, but like Spring AOP it can be very useful in projects that are starting to adopt AOP:
...
@Pointcut("execution(music.model.Playable music.model.PlayableDao.find*(..))")
void createPlayable() {
}
@Around("createPlayable()")
public Playable proxyPlayable(ProceedingJoinPoint pjp) throws Throwable {
Playable created = (Playable)pjp.proceed();
return proxyPlayable(created);
}
public Playable proxyPlayable(Playable playable) {
AspectJProxyFactory factory = new AspectJProxyFactory(playable);
factory.addAspect(this);
if (playable instanceof PlayList) {
proxyChildren((PlayList)playable);
}
return (Playable)factory.getProxy();
}
void proxyChildren(PlayList playList) {
for (ListIteratorit = playList.getEntries().listIterator(); it.hasNext();) {
Playable child = it.next();
Playable proxy = proxyPlayable(child);
it.remove();
it.add(proxy);
}
}
I asked Ramnivas Laddad about ordering advice with transaction-driven annotations. He pointed me to http://forum.springframework.org/showthread.php?t=28459 for some more information (and limitations).
Posted by: Ron Bodkin | October 26, 2006 at 05:30 PM