Reputation: 95
We can use both @AspectJ annotation style to define aspects, as well as the AspectJ Java extension language, which requires us to use the ajc compiler.
What are the reasons that one would want to use the annotation style instead of ajc? It seems to me that a lot of functionality is given up by using annotation style, but not much (if anything) is gained, other than not having to use ajc (what's so bad about having to use ajc?)
Could someone please enlighten me on this topic?
Upvotes: 3
Views: 3128
Reputation: 49085
Both styles (.aj and @AspectJ) have features that the other cannot do.
See this post for something the annotations can do that declarative AspectJ cannot: What is the AspectJ declaritive syntax for overwritting an argument
The .aj files for the most part (other than mentioned above) can do way more. Most notable they can do ITDs (Inter-Type-Definitions aka adding methods and properties to classes).
The biggest reason you would want to use the @AspectJ is that it does not even require compile time weaving (CTW) or even load time (LTW) if you use Spring proxy AOP support. Spring will mimic @AspectJ but at runtime by creating proxies.
I have noticed that Spring, Eclipse (and myself) seem to be encouraging greater use of true AspectJ. I believe this is because the Eclipse plugin has gotten so good. Also with true AspectJ and the @Configurable annotation you can get Spring wiring on instantiated beans. This is how Spring Roo works.
With the Eclipse AspectJ IDE plugin you can see the pointcut references to both styles (@ and aj) and get a very clear idea of what "magic" is happening.
Upvotes: 3
Reputation: 15434
Adding some additional step to your build process is not the easiest and good way. Especially when you have large project. You go away from all java tools and IDE support, which may not supports *.aj syntax.
Upvotes: 2