作用:在启动Web 容器时,自动装配Spring applicationContext.xml 的配置信息。
因为它实现了ServletContextListener 这个接口,在web.xml 配置这个监听器,启动容器时,就会默认执行它实现的方法。在ContextLoaderListener 中关联了ContextLoader 这个类,所以整个加载配置过程由ContextLoader 来完成
pring 在 web 下的入口在配置文件 web.xml 的监听器中
< listener >
< listener-class >
org.springframework.web.context.ContextLoaderListener
</ listener-class >
</ listener >
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:conf/spring/applicationContext.xml</param-value>
</context-param>
上述是在web.xml 中的配置信息。
// 实现了接口 ServletContextListener, 也就是说他必须实现 contextDestroyed, contextInitialized 这两个