In the previous article, we presented three elements and three elements of the design process that make up the SPRINGMVC application. Let's summarize some of the main points of the design process:
- SPRINGMVC abstract the HTTP processing process into one processing unit
- SPRINGMVC defines a series of components (interfaces) that correspond to all processing units
- The SPRINGMVC is run by Dispatcherservlet, and all components are concatenated together
Throughout the process, components and dispatcherservlet always maintain a mutually supportive relationship:
- dispatcherservlet--the entire logical line and is the heart of the whole frame.
- Component--The programmatic representation of logical processing Unit, which plays a connecting role, is the actual bearer of the SPRINGMVC behavior pattern.
In the next two articles in this series, we will discuss dispatcherservlet and component content separately. This article discusses Dispatcherservlet, while the next one focuses on component analysis.
Concerning Dispatcherservlet, we want to start with the structure of dispatcherservlet, then analyze it according to different logic main line, hoping to help readers to sort out the ideas of learning Springmvc core class.
architecture of the Dispatcherservlet
Observing Dispatcherservlet by different angles will result in different conclusions. Here we have selected three different angles: run characteristics, inheritance structure, and data structure.
"Running Mainline"
From the interface realized by Dispatcherservlet, the core essence of Dispatcherservlet is:is a servlet。 This conclusion seems naïve, but the naïve conclusion contains an intrinsic principle that is essential to the entire framework:The servlet can be divided into the main line of operation according to its characteristics。
According to the definition of the servlet specification, the two core methods of the servlet, the Init method and the service method, have distinct runtime and trigger conditions:
1. Init method
run when the entire system is started and run only once. therefore, in the Init method we tend to initialize the entire application. These initialization operations may include initialization of the container (Webapplicationcontext), initialization of components and external resources, and so on.
2. Service Methods
Listens for and processes all Web requests while the entire system is running in a listening mode. So what we see in the service and its related methods is the process of handling HTTP requests.
Thus, this feature of the servlet is SPRINGMVC used to partition different logical functions, thus forming two unrelated logical running lines:
- Initialize the main line--is responsible for initializing the running features of SPRINGMVC
- HTTP request processing Main line--responsible for the logical dispatch of components in SPRINGMVC to complete the processing of HTTP requests
For an MVC framework, the partitioning of the running mainline is very important. Because only by figuring out the different operating lines, we can take different research strategies for different operating lines. And the vast majority of our analysis in this series of points of entry, but also around the different operating lines.
Note : The SPRINGMVC running mainline is based on the life cycle of different methods in the Servlet object. In fact, almost all MVC is based on this as the basis for the division of the main line of operation. This further proves that the core foundation of all MVC frameworks is the servlet specification, and that differences in design concepts lead to different frameworks moving towards a completely different development path.
"Inheritance structure"
In addition to the division of the main line, let's look at the inheritance structure of Dispatcherservlet:
In this inheritance structure, we can see that Dispatcherservlet contains 2 spring support classes in its inheritance tree: Httpservletbean and Frameworkservlet. Let's discuss the role of these two spring support classes here.
Httpservletbean is spring's lowest-level abstraction for servlets. In this layer of abstraction, spring will treat this servlet as a spring bean and inject the value in Init-param as a property of the bean.
This article reproduced in: http://downpour.iteye.com/blog/1341459 inside more detailed
Springmvc delve into (1)--dispatcherservlet and initialize the main line