我正在尝试修改 this example为了我自己的目的。
我想从特定于服务器的文件加载属性,使用如下内容:
<beans:bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<beans:property name="locations">
<beans:list>
<beans:value>${ENV_JDBC_CONFIG}</beans:value>
</beans:list>
</beans:property>
</beans:bean>
其中 ENV_JDBC_CONFIG
是指定属性文件路径的环境变量。
失败并显示
`java.io.FileNotFoundException: Could not open ServletContext resource [/${ENV_JDBC_CONFIG}]`
我怎样才能完成我在这里想做的事情?
最佳答案
使用配置器的 systemPropertiesMode 属性来使用系统属性。
检查this article ,它告诉您管理外部属性的技巧。
如果你想在其他 bean 定义中使用 env 变量,你可以像这样使用它
<bean id="yourBean" class="com.company.YourBean">
<property name="environment" value="#{ systemProperties['env.var1'] }"/>
<!-- other properties goes here....-->
</bean>
关于java - 如何在 propertyConfigurer bean 中引用 ${ENV} var?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29318618/