我最终设法弄清楚了。相反,我要做的是使用一个包含大多数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>
其中properties-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" p:location="classpath:my.properties" /></beans>
servlet-context.xml是常规的Spring servlet上下文文件,它使用$ {}来从my.properties加载的任何属性。



