<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
1.ContextLoaderListener的作用:在启动Web容器时,自动装配Spring applicationContext.xml的配置信息。
参考文档:http://blog.csdn.net/panxuying123/article/details/16910885
网上通常说,listener通常会和context-param一起配合使用,看了上面的文档,如下:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
在全局参数里面配置了classpath:applicationContext.xml的路径,在listener中配置了ContextLoaderListener这个类,之所以说这个类的作用是自动装配Spring applicationContext.xml的配置信息,是因为它实现了一个ServletContextListener接口。在ContextLoaderListener这个监听的类中有个contextInitialized(ServletContextEvent event)的方法,在这个方法中可以通过event.getServletContext().getInitParameter("contextConfigLocation") 来得到context-param 设定的值。所以网上说listener通常会和context-param一起配合使用。