@AspectJ Based AOP with Spring:-
@AspectJ refers to a style of declaring aspects as regular Java classes annotated with annotations. The @AspectJ style was introduced by the AspectJ project as part of the AspectJ 5 release. Spring interprets the same annotations as AspectJ 5, using a library supplied by AspectJ for pointcut parsing and matching. The AOP runtime is still pure Spring AOP though, and there is no dependency on the AspectJ compiler or weaver.
Enabling @AspectJ Support with XML configuration
To enable @AspectJ support with XML based configuration use the
aop:aspectj-autoproxy element:
<aop:aspectj-autoproxy/>
You will also need following AspectJ libraries on the classpath of your
application. These libraries are available in the 'lib' directory of an AspectJ
installation, otherwise you can download them from the internet.
1 aspectjrt.jar
2 aspectjweaver.jar
3 aspectj.jar
Spring AspectJ AOP implementation provides many annotations:
1 @Aspect declares the class as aspect.
2 @Pointcut declares the pointcut expression.
The annotations used to create advices are given below:
1 @Before declares the before advice. It is applied before calling the
actual method.
2 @After declares the after advice. It is applied after calling the
actual method and before returning result.
3 @AfterReturning declares the after returning advice. It is applied
after calling the actual method and before returning result. But you can get the
result value in the advice.
4 @Around declares the around advice. It is applied before and after
calling the actual method.
5 @AfterThrowing declares the throws advice. It is applied if actual
method throws exception.