我试图从环境变量加载属性文件,所以这是我试过的:
<bean id="propertyPlaceholderConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:messages/application.properties</value>
<value>file:${My_ENV_VAR}/*.properties</value>
</list>
</property>
<property name="ignoreResourceNotFound" value="true" />
<property name="searchSystemEnvironment" value="true" />
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
</bean>
Run Code Online (Sandbox Code Playgroud)
我有一个新的环境变量命名,My_ENV_VAR=C:\Program Files\My Folder\props.properties
但在停止和启动应用程序时,没有设置变量的值,任何想法为什么?
更新:要求
我想从文件系统上的外部属性文件中读取applicationContext.xml中的hibernate属性(url,username,password),其路径存储在环境变量中.
您正在尝试使用它PropertyPlaceholderConfigurer来创建PropertyPlaceholderConfigurer.这是一个鸡/蛋问题,它不能工作!
尝试使用表达式语言(参见本节以供参考),但在您的情况下,它很棘手,因为您想要混合静态和动态内容.可能这样的东西会起作用:
<property name="locations"
value="classpath:messages/application.properties,
#{ T(java.lang.System).getenv('MY_ENV_VAR')}" />
<!-- changed method name, it's getenv(), not getEnv() -->
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5721 次 |
| 最近记录: |