Introduction to AOP
AOP is one of the two main features of spring and the IOC. Mainly provides the aspect-oriented programming idea, distinguishes the object-oriented programming.
AOP principle (Dynamic proxy + reflection)
There may be many other method calls in a method body, and we can call each method invocation a connection point. For the target connection point we configured in the expression, we call the pointcut. The execution of each entry point, we can be seen as a one-time stack and into the stack operation. While the program is running, spring dynamically generates a proxy class for the target class in the form of reflection, and the slices are implanted into the proxy object. This allows the proxy class to handle some additional notification events before and after the target method executes.
AOP targets
The ultimate goal of AOP is to achieve complete decoupling of code. Complete modularity makes it easier to develop and manage large projects
Agent
Static proxy: Target interface, target class, proxy class. For large and complex projects, it is a huge project to write too many target proxy classes.
Dynamic Agent:
JDK Dynamic Proxy: Dynamically generated proxy classes, and the target class implements the same interface. (for proxy classes that implement multiple interfaces, there are some drawbacks)
Cglib Dynamic Proxy: Dynamically generated proxy class that inherits the target class.
Reflection
The process of forming an instance object by acquiring a class object in another way.
Spring AOP in-depth analysis