2014-04-29 45 views
0

我正在设置一个Web服务,它将在同一个tomcat中的几个不同的应用程序中重用。我期望做的是有一个设置,我可以重用servlet上下文XML,但只需根据正在设置的servlet获取正确的属性文件即可。我创建了PropertyPlaceholderConfigurer的子类,它允许我从XML中单独请求属性文件,但我无法弄清楚如何从这个类中获取servlet名称。使用相同的servlet环境设置多个Web服务

这甚至可能或者是否有更好的方法来使用Spring MVC 3.2.8来做到这一点?

谢谢

回答

0

我终于弄清楚了这一点。我所做的只是使用包含大多数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加载。

相关问题