我尝试在位于我的jpa-spring.xml
文件中的'PropertyPlaceholderConfigurer'中获取Tomcat的server.xml
中指定的环境变量。如何在PropertyPlaceholderConfigurer中获取tomcat环境变量
到目前为止,设置如下所示:
Tomcat的server.xml
<Environment description="Identifies the server environement"
name="server-env"
type="java.lang.String"
value="dev" />
中WebContent/META-INF/context.xml
:
<Context>
<ResourceLink name="server-env" global="server-env" type="java.lang.String"/>
</Context>
这是WebContent/WEB-INF/web.xml
引用,如:
<resource-env-ref>
<description>Identifies server environement</description>
<resource-env-ref-name>server-env</resource-env-ref-name>
<resource-env-ref-type>java.lang.String</resource-env-ref-type>
</resource-env-ref>
<!-- Spring Integration -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/jpa-spring.xml
</param-value>
</context-param>
而在/WEB-INF/config/jpa-spring.xml
我试图让该变量作为替代:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>WEB-INF/config/db.${server-env}.properties</value>
</list>
</property>
</bean>
这是一个设置我放在一起使用从网络上找到几篇文章的信息。
不过,我得到了如下的错误...
Could not resolve placeholder 'server-env' in [WEB-INF/config/db.${server-env}.properties] as system property: neither system property nor environment variable found
05 Nov 2011 14:45:13,385 org.springframework.web.context.ContextLoader
ERROR Context initialization failed
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/config/db.${server-env}.properties]
...起tomcat的时候。
什么是正确的方法来实现我在找什么?
我知道这个问题类似于this和this的问题。但是,我甚至无法用这些答案中的信息弄清楚。
你正在使用哪个版本的Spring? – Santosh