springmvc启动流程
2022-04-02 21:29:18 4 举报
第一版
作者其他创作
大纲/内容
onStartup
AbstractAnnotationConfigDispatcherServletInitializer.createRootApplicationContext
servletContext.addListener(listener)
listener = new ContextLoaderListener(rootAppContext)
AbstractAnnotationConfigDispatcherServletInitializersuper.onStartup
dispatcherServlet.setContextInitializers(getServletApplicationContextInitializers()=null);
Filter[] filters = getServletFilters() = null;
获取spring-mvc.xml的配置信息1.创建空的子容器AnnotationConfigWebApplicationContext2.用子容器创建DispatcherServlet3.设置ContextInitializers,但是实际设置的是null,可能留着拓展用3.DispatcherServlet加到servletContext里面4.获取过滤器,也是null,并遍历
createDispatcherServlet(servletAppContext)
获取spring-bean.xml的信息1.先创建 AnnotationConfigWebApplicationContext 作为父容器,是空的2.创建ContextLoaderListener,并将父容器传入listener3.给ContextLoaderListener设置ContextInitializers,但是实际设置的是null,可能留着拓展用4.servletContext将listener加入进来
先配置一些属性,让父容器相当于一个web.xml再让父容器refresh
循环遍历所有WAI的实现类,过滤掉接口和抽象类,
@HandlesTypes(WebApplicationInitializer.class)指定处理WebApplicationInitializer接口下的所有实现类
configureAndRefreshWebApplicationContext
AbstractContextLoaderInitializer.registerContextLoaderListener(servletContext)注册一个listener
ContextLoader.initWebApplicationContext
AbstractDispatcherServletInitializer.registerDispatcherServlet(servletContext);注册一个DispatcherServlet
根据SPI规范,在META-INF下创建 javax.servlet.ServletContainerInitializer文件,文件中的内容是 org.springframework.web.SpringServletContainerInitializer
ContextLoaderListener.contextInitialized()
循环调用启动器的onStartup
ReflectionUtils.accessibleConstructor(waiClass).newInstance()将剩下的具体实现类通过构造器进行反射实例化并放入list中:initializers
listener.setContextInitializers(getRootApplicationContextInitializers()=null);
AbstractAnnotationConfigDispatcherServletInitializercreateServletApplicationContext()
AnnotationAwareOrderComparator.sort(initializers)根据@Order和Ordered接口将list进行排序
收藏
0 条评论
下一页