spring 在web.xml 里面如何使用多个xml配置文件
2017-11-07 11:32
696 查看
在web.xml中定义 contextConfigLocation参数.spring会使用这个参数加载.所有逗号分割的xml.如果没有这个参数,spring默认加载web-inf/applicationContext.xml文件.
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-config.xml,classpath:spring-cxf.xml,classpath:spring-quartz.xml
</param-value>
</context-param>
原理:
Spring 提供ServletContextListener 的一个实现类ContextLoaderListener ,该类可以作
为listener 使用,它会在创建时自动查找WEB-INF/ 下的applicationContext.xrnl 文件。因
此,如果只有一个配置文件,并且文件名为applicationContext.xml ,则只需在web.xml
文件中增加如下代码即可:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
如果有多个配置文件需要载入,则考虑使用<context-para即元素来确定配置文件的
文件名。由于ContextLoaderListener加载时,会查找名为contextConfigLocation的参数。
因此,配置context-param时参数名字应该是contextConfigLocation。
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-config.xml,classpath:spring-cxf.xml,classpath:spring-quartz.xml
</param-value>
</context-param>
原理:
Spring 提供ServletContextListener 的一个实现类ContextLoaderListener ,该类可以作
为listener 使用,它会在创建时自动查找WEB-INF/ 下的applicationContext.xrnl 文件。因
此,如果只有一个配置文件,并且文件名为applicationContext.xml ,则只需在web.xml
文件中增加如下代码即可:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
如果有多个配置文件需要载入,则考虑使用<context-para即元素来确定配置文件的
文件名。由于ContextLoaderListener加载时,会查找名为contextConfigLocation的参数。
因此,配置context-param时参数名字应该是contextConfigLocation。
相关文章推荐
- spring 在web.xml 里面如何使用多个xml配置文件
- 如何使用多个Spring的xml配置文件
- spring如何使用多个xml配置文件
- 如何配置Spring的XML文件及使用
- spring如何使用多个xml配置文件
- spring如何使用多个xml配置文件
- spring如何使用多个xml配置文件
- spring如何使用多个xml配置文件
- spring如何使用多个xml配置文件 【转】
- 如何使用多个Spring的xml配置文件(多模块配置)
- spring如何使用多个xml配置文件
- Spring-property文件配置方法以及如何与工程分离~xml使用${}
- 关于项目中web.xml配置文件里面的spring的配置contextConfigLocation
- spring如何使用多个xml配置文件
- spring如何使用多个xml配置文件
- 如何使用多个Spring的xml配置文件
- spring如何使用多个xml配置文件 【转】
- 如何使用Javaconfig代替web.xml配置spring
- 如何将Spring的配置文件放到web.xml中
- JavaEE 下面使用Spring 时 web.xml 中ContextLoaderListener的作用及配置,多个配置文件时contextConfigLocation的作用