I was doing some Spring AOP stuff the other day using @AspectJ style annotations. One of the limitations of Spring AOP is that it supports only method level interception. We cannot intercept Constructors or fields. For that we’ll have to use AspectJ, and different compilers may be – for load time weaving or compile time weaving. I decided to stick to Spring restrictions though.
Here are a couple of cheatsheets/examples for AspectJ. (Remember Spring AOP has limitations, but AspectJ doesn’t).
To start off a project just start a new Spring Boot project from STS with Spring AOP ticked. Thats it. Spring Boot handles all the dependencies bootifully. It adds some unnecessary dependencies also. So if you just need AOP, just add AOP dependencies instead of Spring Boot.
Even though I had heard about AOP, I didn’t take it seriously. I thought it was meant for Enterprise applications usage like Transaction management, logging etc. But recently I was faced with a problem – how to know an Object’s state changes in Java. As you know state of an Object is its properties, so what I want is to know when the state changes. I didn’t quite get what to do about it, and so posted in stackoverflow. And the answer was to use AspectJ!
Here is the link to SO – http://stackoverflow.com/q/16352838/952511
To do AspectJ development in Eclipse we have to install AJDT(AspectJ Development Tools). Just add the correct URL from http://www.eclipse.org/ajdt/downloads/ for the Eclipse version we are using, to ‘Install New Software’ in Help menu and install AJDT n its tools from the list.
And now am learning AspectJ – joinpoints and pointcuts!