在启动Web容器时,自动装配Spring applicationContext.xml的配置信息
因为它实现了ServletContextListener这个接口,在web.xml配置这个监听器,启动容器时,就会默认执行它实现的方法。
在ContextLoaderListener中关联了ContextLoader这个类,所以整个加载配置过程由ContextLoader来完成
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
默认: /WEB-INF/applicationContext.xml
//如果路径/名称不一致, 需要增加配置
//spring*.xml : 表示spring开头的所有xml配置文件全部自动装配
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring*.xml,/WEB-INF/applicationContext.xml</param-value>
</context-param>
web.xml配置ContextLoaderListener作用(转载)
最新推荐文章于 2022-09-25 18:49:37 发布