注:本文梳理启动流程使用的Spring版本:4.0.2.RELEASE 使用spring配置,都需要在web.xml中配置一个spring的监听器和启动参数(context-param),如下:
<context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:spring-*.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
web容器启动时,下面为spring加载执行步骤:
- 执行web.xml中的ContextLoaderListener监听器
- 初始化ContextLoaderListener中的contextInitialized方法

- contextInitialized方法中调用父类(ContextLoader)的initWebApplicationContext方法

- initWebApplicationContext方法中执行了三个任务
1.创建WebApplicationContext容器
2.加载context-param中配置的spring配置文件
3.初始化配置文件中及创建配置文件中的bean
- web容器停止时候会执行ContextLoaderListener的contextDestroyed方法销毁context容器
博客介绍了使用Spring配置时,需在web.xml中配置监听器和启动参数。阐述了Web容器启动时,Spring加载执行步骤,包括执行监听器、初始化方法、创建容器、加载配置文件和初始化bean等;还说明了容器停止时会销毁context容器。
168万+

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



