Spring aop considerations

Source: Internet
Author: User

Spring aop has JDK dynamic proxy and CGLIB, and can also use ASPECTJ.

Its JDK dynamic proxy is the interface proxy, while cglib is the proxy for the class. AspectJ is woven into the source code class.

The cglib proxy is used to call the constructor of the target object twice. JDK dynamic proxy and aspectJ are called only once.

In this way, when the cglib proxy is used and the default no-argument constructor of the target object is used for Resource Initialization, initialization may occur twice (based on the business scenario, it is assumed that only one Initialization is allowed ).

Test code:

Configure aop in xml:



Id = "loggerPointcutOfService"/>








In the class B constructor, the output is:

In B construtor

When calling the corresponding method of code object B:

Output:

In B construtor

In B construtor



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.