Java Dynamic proxy implementation

Source: Internet
Author: User

Currently, there are two main methods to implement dynamic proxy in Java:

A. Implement Dynamic proxy through the related classes in the Java. Lang. Reflect package

B. implemented through the open-source framework cglib, which is more flexible to implement


Cglib (code generation Library) is a powerful, high-performance, high-quality code generation class library. It can expand Java classes and implement Java interfaces at runtime.
Cglib encapsulates ASM and can dynamically generate new classes at runtime.
Cglib is used for AOP. The proxy in JDK must be based on the interface, but cglib does not have this restriction.

 

Cglib is the underlying implementation of some frameworks, such as the core packages that spring and hibernate depend on. However, cglib is not the underlying, because it is encapsulated on the ASM package, to enhance ease of use.

 

It is understood that hibernate3.2 no longer depends on cglib, but directly relies on ASM. These do not affect the powerful functions of cglib.

 

The bottom layer of cglib is the Java bytecode operating framework-ASM.

 

The following is an example of how to implement dynamic Proxy:

 

To be continued ....................

 

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.