The implementation principle of Spring container AOP--Dynamic agent

Source: Internet
Author: User
Tags aop

We all know that the two main features of spring are IOC and AOP.

IOC is responsible for the dynamic injection of the object into the container, so as to achieve a need to inject who who, when the need to inject the effect of the time, can be described as a recruit, the lingering. Think all feel cool, if the real life also has this ability that is cool crooked, as for how cool, you own brain repair it, and AOP, it is to achieve the container is another great advantage, that is, you can let the objects in the container to enjoy the public services in the container. So how did the container do it? How can it let the object in it automatically have the public service it provides? The answer is what we're going to talk about today--dynamic proxies.

Dynamic agent is not something new, the person who has learned the design pattern should know the proxy mode, the proxy mode is a static proxy, and the dynamic agent is to use reflection and dynamic compilation to turn the proxy mode into dynamic. The principle is the same as the dynamic injection, the proxy mode at compile time has determined that the proxy class will be agent who, and the dynamic agent in the run time only know who to proxy.

There are two types of dynamic agents in spring: One is the dynamic agent of the JDK, and the other is the Cglib dynamic proxy (which implements the proxy by modifying the bytecode). Today we mainly discuss the way of the JDK dynamic proxy. The main way to do this is through reflection and dynamic compilation, so let's look at the code to see how it is implemented.

The implementation principle of Spring container AOP--Dynamic agent

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.