atitit Agent CGLIB Dynamic proxy aspectj static proxy differences
1.1. Span style= "font-family:arial; Color: #ff0000; Font-size:10.5pt ">a op agent is divided into static agents and dynamic agents of two major categories, static proxy to ASPECTJ   spring  AOP   1
1.2. JDK Dynamic agent is the way to simulate the implementation of an interface,cglib is the way to emulate subclass inheritance 1
1.3. The drawbacks of the CGLIB proxy mode are not possible to apply crosscutting concerns on static and final methods. 2
1.1.A
The OP agent is mainly divided into static agent and dynamic agent, and static agent is represented by AspectJ , while dynamic agent is
Spring
AOP as the Representative
cglib dynamic proxies are available for interfaces with ordinary classes (inheritance mode), and the underlying uses the ASM framework to generate bytecode to complete the proxy function
I checked the information online. ASPECTJ is a static proxy that generates a class file during compilation to complete the proxy. This is easy to understand a compilation technique
because Spring supports ASPECTJ-style AOP
or dynamic, the label used in the Joinpoint and other classes are from the ASPECTJ package
1.2.
The JDK Dynamic agent is the way to simulate the implementation of the interface,cglib is the way to simulate subclass inheritance
JDK Dynamic agent is the way to simulate the implementation of the interface, Cglib is the way to simulate subclass inheritance, the former is generally used, because the former efficiency is high. The latter is not recommended unless it is not
AOP(Aspect Orient programming), as a complement to object-oriented programming, is widely used to handle some system-level services with crosscutting properties, such as transaction management, security checks, caching, Object pool management, and so on. the key of AOP implementation is the AOP proxy created automatically by AOP Framework, and theAOP agent can be divided into static agent and dynamic agent. , where static proxies are compiled using the commands provided by the AOP Framework toCompile PhaseYou can generate an AOP proxy class, which is also known as compile-time enhancements, while dynamic agents " temporary " generation in memory at run time with the help of JDK dynamic agent,CGLIB , etc. AOP dynamic proxy class, so also known asrun-Time enhancements.
The difference is just the build the timing of the AOP proxy classes is different:AspectJ generates an AOP proxy class at compile time , so it has better performance but needs to be handled with a specific compiler; Spring AOP run-time generation is used AOP proxy class, so there is no need to use a specific compiler for processing. Because Spring AOP needs to generate an AOP Proxy each time it runs, performance is slightly worse.
1.3.
Disadvantages of CGLIB proxy mode It is also impossible to apply crosscutting concerns on static and final methods.
because Spring is based on the proxy pattern (using Cglib), which has a usage limit, that is, you cannot apply crosscutting concerns on beans that use final adornments. Because the proxy needs to inherit from the Java class, it cannot be done once the keyword final is used.
For example, in Use the keyword final on Spring bean Myservicesimpl and Configure a "execution (public * * (..))" Such a pointcut will result in a run-time exception (exception) because spring cannot generate a proxy for Myservicesimpl.
in this case, you might consider using AspectJ, which supports compile-time weaving and does not require a build agent.
Similarly, it is not possible to apply crosscutting concerns on static and final methods. Because spring is based on proxy mode. If you configure notifications on these methods, you will cause a run-time exception because the static and final methods cannot be overwritten. In this case, you will also consider using ASPECTJ because it supports compile-time weaving and does not require a build agent.
AOP Log, Record call class, method, method parameter name, method parameter value (including object and base type) -paincupid 's column - Blog channel -CSDN . Net.html
author ::  nickname : old Javanese claws claw of Eagle Idol wreck Iconoclast image-smasher
  attilax akbar   Attilax   " baroque
Full Name: Attilax bin Mahmud bin Attila bin Solomon Akbar Al Rapanui
Attilax this Mahmoud this Attila Solomon Akbar al Rapa Nui
Common name : Etila ( Ayron) , email:[email protected]
reprint Please indicate source: attilax 's Column http://www.cnblogs.com/attilax/
--atiend
Atitit Agent cglib Dynamic proxy aspectj static proxy difference