In this repo, you will find details about spring aspect-oriented programming.
Spring is used to implement cross cutting logic.
Uses proxy design pattern.
Supports only run-time weaving.
Note: In-case if your looking for more flexibility in using aspect use AspectJ. Spring AOP is a subset of AspectJ.
- Aspect: Implementation of cross cutting logic.
- Advice: Define when the cross cutting implementation should be executed (i,e) lifecyle . Refer to advice type section for more details.
- Pointcut: predicate expression.
- JoinPoint: details about method signature and arguments.
- @Before : logic gets executed before method.
- @AfterReturning : logic gets executed only after successful execution of the method.
- @AfterThrowing: logic gets executed when an exception is thrown. (Exception can only be intercepted but not allowed to be modified).
- @After: logic gets executed after completion of the method despited success or failure.
- @Around: logic gets executed both during method start and end. However this type offers a handler to execute the actual method.
-
Include the following dependency as part of maven.
<dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> </dependency>
-
Include the following annotation. @EnableAspectJAutoProxy in Spring root file.
-
Provide Component Scan details for scanning the aspects Ex: @ComponentScan("com.spring.aop.examples")
modifier(?) return-type fully-qualified-class-name(?) methodName ( method-arguments ) exception(?)
Note:
? is optional.
* is a wildcard for any pattern match
The following parameters can be used to match the patterns.
(..) -> 0 or n arguments.
(*) -> exactly 1.
() -> no arguments.