响应式网站建设代理,有域名有网站怎么解决办法,山西建设部网站,网页设计软件dw免费下载分析Spring容器启动流程 Spring初始化
每当启动Web容器时#xff08;例如Tomcat#xff09;#xff0c;会读取Web应用中的web.xml文件。以下这段代码就是启动Spring容器的关键代码。 ContextLoaderListener 类继承了ContextLoader#xff0c;实现 了ServletContextListen…分析Spring容器启动流程 Spring初始化
每当启动Web容器时例如Tomcat会读取Web应用中的web.xml文件。以下这段代码就是启动Spring容器的关键代码。 ContextLoaderListener 类继承了ContextLoader实现 了ServletContextListener接口。
public class ContextLoaderListener extends ContextLoader implements ServletContextListener {public ContextLoaderListener() {}public ContextLoaderListener(WebApplicationContext context) {super(context);}public void contextInitialized(ServletContextEvent event) {this.initWebApplicationContext(event.getServletContext());}public void contextDestroyed(ServletContextEvent event) {this.closeWebApplicationContext(event.getServletContext());ContextCleanupListener.cleanupAttributes(event.getServletContext());}
}
ContextLoaderContextLoaderListener可以指定在Web应用程序启动时载入Ioc容器正是通过ContextLoader来实现的ContextLoader来完成实际创建的WebApplicationContext也就是Ioc容器的初始化工作。 ServletContextListener负责监听ServletContext域的创建和销毁当域创建时会调用contextInitialized方法(继承自ContextLoader)。创建WebApplicationContextweb应用上下文对象并放入ServletContext域中以便调用。
这就是Spring容器的启动流程了。