[sping reveal] 11. AOP implementation mechanism on the Java platform

 

Dynamic proxy

 

Jdk1.3 only has the dynamic proxy mechanism introduced, which can dynamically generate corresponding proxy objects for the corresponding interfaces (must have interfaces) during operation

Based on the above problems, we can encapsulate the cross-cutting concern logic into the invocationhandler of the dynamic proxy.

 

The performance is definitely not better than the execution of static classes, after all, this is using reflection during runtime

 

 

Dynamic Bytecode Enhancement Technology

 

 

With the help of CGLIB, the class file of the bytecode is dynamically constructed for execution directly during the running of the program

However, if the class that needs to be extended and the instance methods in the class are declared final, then it cannot be extended by subclassing.

 

When Spring aop cannot use the dynamic proxy mechanism to expand the AOP function, it will use the enhancement of the dynamic bytecode of the CGLIB library to realize the function expansion of AOP

 

 

Java code generation

 

For example, according to the weaving information provided by the deployment descriptor file, EJB will generate corresponding java code for the corresponding function module class according to the information provided by the descriptor, and then compile the java code through the deployment tool or deployment interface to generate the corresponding java class.

 

 

 

custom class loader

 

Class must be loaded into the java virtual machine through the corresponding class loader (Classloader) before it can run.

 

We can complete the weaving of cross-cutting logic into the system by customizing the class loader. The custom class loader can add cross-cutting during the loading of the class file by reading the weaving rules and necessary information specified by the external file. into the existing logic of the system module class, and then hand over the modified class to the java virtual machine to run.

 

Guess you like

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