Open Tao Spring3 (6.9)-AOP 6.9 proxy mechanism

Source: Internet
Author: User

Spring AOP is implemented in proxy mode and currently supports two types of proxies: JDK dynamic agent, cglib Agent to create an AOP proxy, and Spring recommends the use of JDK dynamic proxies.

    • JDK Dynamic Proxy: uses the java.lang.reflect.Proxy dynamic proxy implementation, which is to extract the interface of the target object and then create an AOP proxy on the interface.
    • CGLIB Agent: Cglib agent can not only interface agent, also can carry out class agent, cglib agent need to pay attention to the following issues:

The final method cannot be notified because the final method cannot be overwritten (Cglib creates the proxy by generating subclasses).

Generates two constructor calls, the first of which is the constructor call of the target class, and the second is the constructor call of the cglib generated proxy class. If you need to Cglib proxy methods, make sure that two constructor calls do not affect the app.

Spring AOP defaults to using the JDK dynamic proxy first to proxy the target object, if the target object does not implement any interface will use the Cglib proxy, if you need to force the use of the Cglib proxy, use the following way to specify:

For schema-style configuration facets, use the following method to specify the use of the Cglib proxy:

<proxy-target-class= "true">  </aop:config  >

If you use the @aspectj style, use the following method to specify the use of the Cglib proxy:

    <proxy-target-class= "true"/>  

Open Tao Spring3 (6.9)-AOP 6.9 proxy mechanism

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.