In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces how to analyze the design and principle of Spring AOP. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
Java program execution-method call
In learning the basics of java, we know that a java program always starts with the main method. When it starts running, JVM creates a main thread, and the main thread starts to execute code with the main method as the entry. From a thread stack point of view, the basic unit of JVM processing Java programs is method calls (macroscopic). When we use object-oriented to solve problems, we are thinking about how to implement our business logic through method calls in the order of execution. If you consider the execution of Java programs from the perspective of virtual machine thread stack, you will find that the whole process of running the program is the process of method calls.
Connection point
If we arrange the method calls in the above thread stack according to the execution flow, we will have a diagram similar to the following:
Based on the order in which the program runs, we can line up the calls to the method. Each method call can be seen as a node on this line. This node is called Join Point, or join point, in AOP terminology. The process of running a Java program is a process in which several connection points are connected and executed in sequence.
Facet / pointcut
AOP (Aspect Oriented Programming) considers the whole program from another point of view. AOP takes every method call, that is, the connection point, as the entry point for programming. From the point of view of the logic of execution, it is equivalent to the horizontal cut of the program executed according to the timeline before. It is equivalent to cutting the previous program horizontally into several faces, that is, Aspect. Each face is called a section.
Because the aspect is essentially every method call, the process of selecting the section is actually the process of selecting the method. Then, the selected facet (Aspect) is called a Point Cut in AOP terminology. Pointcuts are actually the process of selecting the Join point you are interested in from all the join points.
Proxy pattern implements AOP
Since AOP is programming method calls, the question is, how does AOP capture method calls? In other words, how does AOP know which method is currently running? In order to understand this problem, you have to understand the agent pattern in the design pattern! What is the agent mode? For example: the real example object is first to Dili Reba. When Dili Reba is not on fire, she goes by herself, which is equivalent to when there was no agent before. now having an agent is equivalent to having an agent. If you want Dili Reba to dance, you have to contact the agent first. We assume that in our Java code, proxy objects are created for instance objects through the proxy pattern, and access to these instance objects must be through proxies, then the Java program execution flow that adds proxy objects (proxy roles) becomes a little more complicated.
Now that the Spring proxy layer is aware of every method call you make to the instance object, Spring has a chance to insert Spring's own business code in the process of the proxy.
On how to analyze the design and principles of Spring AOP to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.