On the source code analysis of the article, I feel that the efficiency of reading learning is not high. Without the reality of brain maps, self-learning from the top down can greatly increase learning efficiency. Springboot series articles only put dry goods, no nonsense. Pictures for collection only, reprint please indicate the source, thank you friends!

Mind mapping

conclusion

  • WebMvcAutoConfigurationIs Springboot’s auto-loading WebMvc entry, which can be passedspring.factoriesThe configuration file is known.
  • WebMvcAutoConfigurationBefore loading,@AutoConfigureAfterWill be loadedDispatcherServletAutoConfigurationAnd theDispatcherServletAutoConfigurationIt loads before it loadsServletWebServerFactoryAutoConfiguration

  • WebMvcAutoConfigurationloadsEnableWebMvcConfigurationWebMvcAutoConfigurationAdapterThe two inner class creation and configuration are includedMessage converter,View parser,Processor mapper,Processor adapter,Static resource mapping configurationAnd so on.
  • SpringBoot determines which components to assemble and which type of Web container to start based on the classes in the current classpath
  • In addition to properties and YML files, SpringBoot applications can be configuredCustomizerCustomize programmatic configuration.

SpringMvc execution process

1.DispatcherServletRepresents the front controller, which is the control center for the entire SpringMVC. The user makes a request,DispatcherServletReceive the request and intercept the request.

2.HandlerMapping Indicates processor mapping. DispatcherServlet call HandlerMapping HandlerMapping, according to the request url search Handler

HandlerExecution is a Handler that searches for a controller based on its URL. The controller whose URL is searched is input-product

HandlerExecution passes parsed information to the DispatcherServlet, such as parsing controller mappings

5.HandlerAdapter represents a processor adapter that executes handlers according to specific rules

6.Handler makes the specific Controller execute

7. The Controller returns the specific execution information to the HandlerAdapter, such as ModelAndView

8. The HandlerAdapter passes the view logical name or model to the DispatcherServlet

9. The DispatcherServlet calls the ViewResolver to resolve the logical view name passed by the HandlerAdapter

10. The view parser passes the parsed logical view name to the DispatcherServlet

11. The DispatcherServlet invokes a specific view based on the view result parsed by the view parser

12. The final view is presented to the user.

Of course, ViewResolver is not always used in daily development. Most of the time, it returns JSON data. @responseBody in @restController is going to take care of that for us.

/**
 * Annotation that indicates a method return value should be bound to the web
 * response body. Supported for annotated handler methods.
 *
 * <p>As of version 4.0 this annotation can also be added on the type level in
 * which case it is inherited and does not need to be added on the method level.
 *
 * @author Arjen Poutsma
 * @since 3.0
 * @see RequestBody
 * @see RestController
 */
Copy the code