spring ioc aop

Understanding of spring

Spring is a lightweight framework, which, to put it bluntly, is a hodgepodge, providing the integration of various popular frameworks.

Ioc, which transfers the creation and dependencies of classes from the original new to spring for processing, realizing loose coupling

aop abstracts functions that are relatively independent from program logic, such as security and transaction, and uses spring to embed these functions, which realizes programming according to aspects and improves reusability.

AOP implementation

Aop proxy is mainly divided into static proxy and dynamic proxy. The representative of static proxy is AspectJ; while the dynamic proxy is represented by Srping AOP.

There are two main ways of dynamic proxy in Spring AOP, JDk dynamic proxy and cglib dynamic proxy. The JDK dynamic proxy receives the proxied class through reflection, and requires that the proxied class must implement an interface. The core of the JDK dynamic proxy is the InvocationHandler interface and the Proxy class.

If the target class does not implement the interface, Spring AOP will choose to use CGLIB to dynamically proxy the target class. CGLIB is a code-generated class library that can dynamically generate subclasses of a class at runtime. Note that CGLIB is a dynamic proxy through inheritance, so if a class is marked as final, it cannot use CGLIB as a dynamic proxy.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325435159&siteId=291194637