在web.xml里面,都会有下面这段代码:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- Bootstraps the root web application context before servlet initialization -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
ContextLoaderListener容器加载器会自动读取<param-value>标签下载的配置文档,这是因为ContextLoaderListener监听器实现了ServietContextListener接口,这个接口在服务器启动的时候就会自动启动,等到服务器结束的时候也就会跟着自动结束了。