“This is the 16th day of my participation in the First Challenge 2022. For details: First Challenge 2022.”
Follow up on process analysis related to previous SpringMVC framework technologies
Initialization process (initStrategies)
Execute the process
Find related HandlerMapping
Request the DispatcherServlet class to execute the relevant HandlerMapping collection, find the corresponding type of HandlerMapping object implementation class, If it is a general use of annotations (@ RequestMapping) injection implementation class (RequestMappingHandlerMapping) class,
The RequestMappingHandlerMapping objects of the HandlerMapping implementation class
Find the beans in the Spring container that are decorated with the @Controller/@RestController annotation and the classes and methods that are decorated with the @requestMapping annotation.
The HandlerMethod object of the HandlerMapping property
HandlerMethod is the helper class for methods and parameters. Is constructed in HandlerMapping and used in HandlerAdapter.
HandlerExecutionChain object
After obtaining the implementation class of the corresponding HandlerMapping object, we then return to the DispatcherServlet class object and need to build or obtain the relevant HandlerExecutionChain object, which contains many additional components, such as: Interceptor Interceptor.
HandlerAdapter object
According to the Handler in the HandlerExecutionChain, find the corresponding HandlerAdapter that supports this Handler and call the corresponding HandlerMethod object method. Use the HandlerAdapter to get the ModelAndView object back to the DispatcherServlet.
RequestMappingHandlerAdapter
Find the corresponding RequestMapping HandlerAdapter object implementation class RequestMappingHandlerAdapter object processing operation.
HandlerInterceptor interceptor
- Front-end interceptor: HandlerInterceptor-prehandle
- Rear interceptor: HandlerInterceptor-postHandle
HandlerExceptionResolver Exception handling
Exceptions may occur in the preceding operations. Use the HandlerExceptionResolver policy.
RequestMappingHandlerAdapter processing operations
- HandlerMethodArgumentResolverComposite: the object processing and collection contains more than internal HandlerMethodArgumentResolver.
- HandlerMethodArgumentResolver: parsing methods entrance parameter parsing mechanism!
- HandlerMethodReturnValueHandlerComposite: the object processing and contains multiple internal HandlerMethodReturnValueHandler collection.
- HandlerMethodReturnValueHandler: the object processing and operating methods return values
HandlerMethodArgumentResolver parameters of the entrance to the parser
RequestParamMethodArgumentResolver
Processing @ RequestParam annotations to modify parameters: one of the implementation class HandlerMethodArgumentResolver: RequestParamMethodArgumentResolver.
RequestResponseBodyMethodProcessor
Processing @ RequestBody annotations to modify parameters: HandlerMethodArgumentResolver implementation class
Returns the parser operation HandlerMethodReturnValueHandler parameters
RequestResponseBodyMethodProcessor
Processing @ ResponseBody annotations to modify the return value: HandlerMethodReturnValueHandler implementation class
ModelAndViewMethodReturnValueHandler
Handle return value types for ModelAndView object return values: HandlerMethodReturnValueHandler implementation class
ViewResolver ViewResolver
The object data of ModelAndView and data page template are parsed and processed by ViewResolver object to generate relevant View object. And return the relevant response: freemarker, jsp. json, XML, etc.
ViewResolver
The View resolver is responsible for generating a View from the result of processing. The ViewResolver first resolves the logical View name into the physical View name (the specific page address).
It is generated into a View (HTML/JSON/XML) and returned to the CPU, which presents the result to the user in the form of a page.
There are several View types available in SpringMVC, such as JstlView, RedirectView, and so on.
The final handling of the HandlerInterceptor
Finish the interceptor: afterCompletion method operation.
conclusion
Personal summary draws out a related core process distribution execution diagram: