我终于弄清楚了这一点。我所做的只是使用包含大多数servlet配置的单个XML文件,然后使用单个XML文件来设置要使用的属性文件。然后在web.xml中,我指定了Servlet的param-value中的两个XML文件,并且它们都被加载并使用正确的属性文件。例如。 web.xml中
<servlet>
<servlet-name>myAppServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/properties-context.xml /WEB-INF/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
,其属性-context.xml的
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" p:location="classpath:my.properties" />
</beans>
和servlet-context.xml的是一个普通的春天servlet上下文文件,该文件使用$ {}任何场所,my.properties加载。