Spring AOP versus AspectJ
So far, we have seen AOP using proxy patterns and runtime weaving. Now let's look at AOP at compile time and load time weaving.
What is AspectJ?
As we know from the start of this chapter, AOP is a programming paradigm that helps to decouple our code by separating the implementation of crosscutting concerns. AspectJ is the original implementation of AOP, which implements both concerns and the weaving of crosscutting concerns using extensions of Java programming language.
To enable AspectJ in our project, we need AspectJ libraries and AspectJ provides different libraries based on its usage. One can find all its libraries, at https://mvnrepository.com/artifact/org.aspectj.
In AspectJ, Aspects
will be created in a file with the extension .aj
. The following is the sample TransferAspect.aj
file:
public aspect TransferAspect {
pointcut callTransfer(Account acc1, Account acc2, int amount) :
call(public * TransferService.transfer(..));
boolean around(Account acc1...