- 监听容器初始化tomcat web.xml 中配置
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
在contextInitialized时候调用 初始化web应用context
/**
* Initialize the root web application context.
*/
@Override
public void contextInitialized(ServletContextEvent event) {
initWebApplicationContext(event.getServletContext());
}
2 然后 创建创建context
this.context = createWebApplicationContext(servletContext);
3 配置和刷新context
configureAndRefreshWebApplicationContext(cwac, servletContext);
4在AbstractApplicationContext.refresh 接口中会初始化容器中的bean
// Instantiate all remaining (non-lazy-init) singletons.
finishBeanFactoryInitialization(beanFactory);
参考文件
https://juejin.im/post/6844903492977442823
https://blog.csdn.net/hl_java/article/details/79698775