Closed Alice52 closed 2 years ago
request
--> DispatcherServlet
DispatcherServlet
--> xxHandlerMapping[Adaptor]
: 确定请求被路由到那个 handler
HandlerExecutionChain
: 执行链+5
HandlerAdatpor
执行 执行链
上的handler: controller 的逻辑再此处执行 +8
+9
DispatcherServlet
得到 ModelAndView, 并使用 View Resolver
处理返回 View
DispatcherServlet
根据得到的 view
进行视图渲染, 并且将 数据 Model
填充到 request
域中doDispach
handleInternal + invokeHandlerMethod + invokeAndHandle
invokeForRequest
resolveArgument
validateIfApplicable
validateIfApplicable
validateIfApplicable
web container auto config theory
<!-- dependency -->
<!-- remove default web container: tomcat -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-tomcat</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- import new web container -->
<dependency>
<artifactId>spring-boot-starter-jetty</artifactId>
<groupId>org.springframework.boot</groupId>
</dependency>
auto config
ServletWebServerFactoryConfiguration ServletWebServerFactoryAutoConfiguration: BeanPostProcessorsRegistrar EmbeddedWebServerFactoryCustomizerAutoConfiguration
step
1. SpringBoot will inject ServletWebServerFactoryConfiguration to create xxFactory when necessary
2. when container create webContainer will call BeanPostProcessorsRegistrar to exectue customize() method
load
execute
Listener
Filter: execute by define order
Interceptor: HandlerInterceptor / HandlerInterceptorAdapter
postHandler called when all interceptors in the interceptor chain execute successfully
if preHandle, must afterCompletion
make two Interceptor execute sequential:
WebMvcConfigurerAdapteror implement WebMvcConfigurer,Servlet[DispatcherServlet]
postHandler