"Sping Revelation" 11, the implementation mechanism of AOP on the Java platform

Source: Internet
Author: User

Dynamic Agent

Jdk1.3 only the introduction of dynamic agent mechanism, can be run again, for the corresponding interface (must have interface) dynamically generated corresponding proxy object

Based on the above problems, we can encapsulate the crosscutting concern logic into the invocationhandler of dynamic agents.

Performance is definitely better than static class execution, after all, this is the use of reflection during run time

Dynamic byte-code enhancement Technology

Execute a class file that dynamically builds bytecode while the program is running, using cglib directly

However, if a class that needs to be extended and an instance method in a class are declared final, then it is not possible to subclass the extension.

When Spring AOP cannot use the dynamic agent mechanism to extend the AOP function, it uses the dynamic bytecode enhancement of the Cglib library to realize the function extension of AOP.

Java code Generation

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

Custom Class Loaders

Class is loaded into the Java virtual machine by the appropriate ClassLoader (Classloader) before it can run.

We can complete the cross-cutting logic to the system by customizing the ClassLoader, and the custom ClassLoader can add the crosscutting to the existing logic of the system module class while loading the class file by reading the rules and necessary information required by the external file. Then give the modified class to the Java virtual machine to run.

"Sping Revelation" 11, the implementation mechanism of AOP on the Java platform

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.