- 監(jiān)聽(tīng)容器初始化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時(shí)候調(diào)用 初始化web應(yīng)用context
/**
* Initialize the root web application context.
*/
@Override
public void contextInitialized(ServletContextEvent event) {
initWebApplicationContext(event.getServletContext());
}
2 然后 創(chuàng)建創(chuàng)建context
this.context = createWebApplicationContext(servletContext);
3 配置和刷新context
configureAndRefreshWebApplicationContext(cwac, servletContext);
4在AbstractApplicationContext.refresh 接口中會(huì)初始化容器中的bean
// Instantiate all remaining (non-lazy-init) singletons.
finishBeanFactoryInitialization(beanFactory);
參考文件
https://juejin.im/post/6844903492977442823
https://blog.csdn.net/hl_java/article/details/79698775