SpringMvc DispatcherServlet details
Running Features
DispatcherServlet: it is a Servlet.
Servlet principle: Servlet can be divided into main lines based on its features
According to the core Servlet method, you can know the main line of DispatcherServlet:
Init
Service
Initialize the Main Line-initialize the runtime elements of SpringMVC
Main Line of Http request processing-it is responsible for logical scheduling of Components in SpringMVC to complete processing of Htt requests.
Inheritance Structure
In this inheritance architecture, HttpServletBean and FrameworkServlet support spring.
HttpServletBean is Spring's abstraction of the Servlet at the lowest level. In this abstraction layer, Spring regards this Servlet as a Spring bean and injects the value in init-param as the bean property.
Conclusion:
FrameworkServlet initializes a Spring container (WebApplicationContext) and
The related operation interfaces are exposed, so the DispatcherServlet inherited from FrameworkServlet can directly communicate with WebApplicationContext.
The Inheritance System of DispatcherServlet builds a bridge between DispatcherServlet and Spring container.
Data Structure
Separated by a horizontal line:
Configure parameters -- control the initialization behavior of SpringMVC Components
Core Component -- SpringMVC core logic processing component
The two important data types involved here involve components, which are the core of DispatcherServlet.
Operating Mechanism
From the inheritance structure and data structure of DispatcherServletServlet, we can see that the inheritance structure establishes a connection with spring, and the data structure is related to the formation. The extraction is the three main components: dispatcherServlet, spring, and components.
IspatcherServlet-container-DispatcherServlet initializes the container
Container-component-container global management of components
DispatcherServlet-component-DispatcherServlet logical call of components
Initialize Main Line
Initialize the Main Line driver-init
Initialize the execution sequence of the Main Line-HttpServletBean-frameworkServlet-DispatcherServlet
Initialize the created operation objects-spring container (WebApplicationContext) and components
WebappplicationContext
The following configuration file should be unique:
Springmvc core components are configured here:
Core distributor Dispatcher
Core configuration file [servlet-name]-servlet. xml and the relationship between them
Use contextConfigLocation to customize the core configuration file of Springmvc. xml
Xml Code
dispatcher
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:web/applicationContext-dispatcherServlet.xml
1
dispatcher
/
Springmvc components are interface definitions, and springmvc defines components as interface implementation classes, just like the Spring management component pattern: use a specific implementation class to specify the interface behavior. Different implementation classes,
It represents different component behavior patterns, which can coexist in Spring containers.
Xml Code
Summary:
WebApplicationContext initialization logic:
1. DispatcherServlet initializes WebapplicationContext
2. WebApplicationContext instantiate components in springmvc
WebApplicationContext System
Root WebApplicationContext
|-Springmvc WebApplicationContext
Roles of DispatcherServlet
Java code: protected void initStrategies (ApplicationContext context) {initMultipartResolver (context); initLocaleResolver (context); handler (context); initHandlerMappings (context); initHandlerAdapters (context ); initHandlerExceptionResolvers (context); initRequestToViewNameTranslator (context); initViewResolvers (context); initFlashMapManager (context );}
Obviously, what DispatcherServlet does is initialization.