Aspect-oriented-programming is a technique that helps to separate the system service(concern) from the core business logic. System services are like logging, security, transaction management, exception handling, etc.
The Advantage of using AOP are:
1)The business component looks very clean having only business logic.
2)All system services are implemented in a commonplace that simplifies code management.
3)Clear separation among the developer.
Every system service is an aspect like logging. exceptions etc.
Advice is the actual implementation of an aspect i.e. it defines the job that an aspect will perform. Advice defines both what and when of an aspect.
|Before||org.springframework.aop.MethodBeforeAdvice||Called before target method is invoked|
|After||org.springframework.aop.AfterAdvice||Called after the target method returns regardless of the outcome|
|Afterreturning||Org.springframework.aop.AfterReturningAdvice||Called after target method completes successfully|
|Around||Org.aopalliance.intercept.MethodInterceptor||Both Before and After|
|Afterthrowing||org.springframework.aop.ThrowsAdvice||Called when target method throws an exception.|
A joinpoint is a point in the execution of the application where an aspect can be plugged in. Spring only supports method joinpoints.
Pointcut help to narrow down the joinpoint instead of applying advice on all the joinpoint.
A proxy is an object created at runtime after applying advice to the target object.
Proxy = target + advice(s)
The target class is a pure business component that is being advised. Without AOP, this class would have to
contain its primary logic plus the logic for any cross-cutting concerns.
The process of applying aspects to a target object to create a new proxied object.
Combining Advice and Pointcut where the advice should be executed is called Advisor.
Advisor = Advice + Pointcut(s)