场景:要求项目的spring配置文件存在 src/springCfg 目录下,struts2的配置文件存放在 src/strutsCfg 目录下
为了实现该场景,在appltionContext.xml文件中的配置如下:
<!--Spring配置-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:springCfg/spring-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- struts2配置 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
support.struts2.filter.CustomStrutsPrepareAndExecuteFilter
</filter-class>
<init-param>
<param-name>configPattern</param-name>
<param-value>classpath*:strutsCfg/struts-*.xml</param-value>
</init-param>
<init-param>
<param-name>configProviders</param-name>
<param-value>support.struts2.config.providers.CustomConfigurationProvider</param-value>
</init-param>
</filter>
注意:通过该方式也可以只加载特定的某个文件作为配置文件