This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
We are prototyping a new system. We are using Spring. And we are using AOP.
According to Rod Johnson in his book J2EE Development Without EJB, he would recomend using Spring's implementation of AOP. But this book is an old 2004 book.
Spring's version is nice because it uses Java interfaces and it seems easier to implement. One downer is that it is a run-time implementation. But I am not sure we need anything more. And we are already locked into using Spring.
The other option is AspectJ. It is a more full implementation of AOP. It is a compile time implementation. But the code is not Java. I have heard that Spring is now recommending, or at least indirectly suggesting, that you use AspectJ in its 2.x releases (2.x has new build in support for AspectJ??).
I know which implementation of AOP you use greatly depends on your project's requirements.
My questions: 1. Based on your experience, do you automatically use one or the other? 2. Is Spring now shifting away from its own implementation and recommending AspectJ? I have not found anything that supports that yet. 3. Have you run into any problems using Spring's AOP implementation?
The squeaky wheel gets the grease. Well, that or replaced...
I can speak to #3, no comments on the two. No, no problems so far. I like it. Nifty way to graft in useful code that otherwise would really obscure what is going on in some classes.
Clearly Spring AOP functionality is a subset of AspectJ functionality. I suspect a day may come when I graduate from one to the other, but no rush at the moment. Maybe someday I'll find another IOC container whose implementation I prefer over Spring but doesn't come with AOP and will switch to AspectJ then, but in the meantime I like it.
Actually Spring and AspectJ versions are highly complementary. Those using Spring AOP find it easy to configure and tend to appy it to coarse-grained service type objects like business layer facade implementations. AspectJ can do the same thing but also proxy fine-grained domain objects. It also has a much more powerful but more difficult to learn pointcut syntax. Spring is NOT moving away from its own versions as both are useful for different things.
Spring 2.0 now has much tighter integration with AspectJ and supports its pointcut syntax as well as its own simple Ant style and Regular Expression pointcut syntaxes. There is also now an AspectJ specific extension of the beans configuration XML that makes it easier to setup and wire aspects into your system. Spring's new XML syntax is now based on a schema instead of a DTD which allows others to extend the syntax in an application specific way. Both AOP frameworks also support Java 5 annotations.
For those just getting started with AOP, Spring's pointcut syntax provides an easy way to get up to speed.
kktec<br />SCJP, SCWCD, SCJD<br />"What we observe is not nature itself, but nature exposed to our method of questioning." - Werner Heisenberg