我終於弄清楚了這一點。我所做的只是使用包含大多數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加載。