前言
上篇【SpringBoot深度探究(九)源码探究启动流程之三】说完了Tomcat启动以后,到目前为止SpringBoot的启动流程就剩下一个问题没有解决,那就是如何把DispatcherServlet和Spring环境联系起来的,那么本篇博客将会把这个问题做一个讲解。更多Spring内容进入【Spring解读系列目录】。
DispatcherServletAutoConfiguration
和之前模拟的一样,首先SpringBoot在启动中new出来,然后再把DispatcherServlet注册到Spring容器中。做这一步事情的组件,就是这一段的标题DispatcherServletAutoConfiguration类初始化之后的结果,首先先看这个类上的注解。
DispatcherServletAutoConfiguration注解
@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE)
@Configuration(proxyBeanMethods = false)
@ConditionalOnWebApplication(type = Type.SERVLET)
@ConditionalOnClass(DispatcherServlet.class)
@AutoConfigureAfter(ServletWebServerFactoryAutoConfiguration.class)
public class DispatcherServletAutoConfiguration {
. . . . . .
}
首先@Configuration注解,说明这是一个配置类,会在Spring容器启动的时候被加载。然后@ConditionalOnWebApplication指定这是一个web项目。之后@ConditionalOnClass,如果发现classpath里面有DispatcherServlet就实例化出来一个bean,这里其实就是在关联Spring环境和DispatcherServlet。最后@AutoConfigureAfter注解说明此类会在ServletWebServerFactoryAutoConfiguration配置之后再进行。然后往下走:
DispatcherServlet Bean & MultipartResolver Bean
public class DispatcherServletAutoConfiguration {
//The bean name for a DispatcherServlet that will be mapped to the root URL "/"
public static final String DEFAULT_DISPATCHER_SERVLET_BEAN_NAME = "dispatcherServlet";
//The bean name for a ServletRegistrationBean for the DispatcherServlet "/"

最低0.47元/天 解锁文章
1486

被折叠的 条评论
为什么被折叠?



