NOTE
What Spring AOP Is
1. What AOP is 2. Implementation principle
This is a historical learning note and may contain outdated or incomplete understanding.
1. What Is AOP?
Aspect-oriented programming. It adds functionality without changing the original code.
Before AOP, if we wanted to add a logging feature, we could directly modify the original code, but that couples business code with other code and makes maintenance difficult.
With AOP, I only need to write the logging code in AOP, and the original code does not need to be changed.
2. Implementation Principle
Spring AOP uses dynamic proxies.
When Spring starts, it creates both the proxy class and the target class. If the target class has an interface, the proxy class uses JDK dynamic proxying; otherwise it uses CGLIB inheritance. Other classes receive the proxy class through dependency injection. When a method is called, execution then goes through the proxy class’s before and after methods.
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub