propertyPlaceHolderConfigurer 和环境变量
我正在尝试从环境变量加载属性文件,所以这就是我尝试过的:
<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>
我有一个名为 My_ENV_VAR=C:\Program Files\My Folder\props.properties
的新环境变量 但是当停止和启动应用程序时,未设置变量的值,有什么想法吗?
更新:要求
我想从文件系统上存储其路径的外部属性文件中读取applicationContext.xml中的休眠属性(url、用户名、密码)在环境变量中。
I am trying to load a property file from an environment variable, so here's what I tried:
<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>
I have a new environment variable named My_ENV_VAR=C:\Program Files\My Folder\props.properties
but when stopping and starting the application the value of the variable is not set, any ideas why?
UPDATE: Requirement
I want to read the hibernate properties (url,username,password) in the applicationContext.xml from an external property file on file system, which its path is stored in an environment variable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在尝试使用
PropertyPlaceholderConfigurer
创建PropertyPlaceholderConfigurer
。这是先有鸡还是先有蛋的问题,不行!尝试使用表达式语言(请参阅 本节供参考),但就您而言,这很棘手,因为您想混合静态和动态内容。也许这样的事情会起作用:
You are trying to use the
PropertyPlaceholderConfigurer
to create thePropertyPlaceholderConfigurer
. That's a chicken / egg problem, it can't work!Try expression language instead (see this section for reference), but in your case it's tricky because you want to mix static and dynamic content. Probably something like this will work:
你应该使用这种方式:
首先声明 spring bean
现在在 WEB-INF/classes 目录中创建文件 config.properties 并放入以下内容:
注意:当我部署 JBoss 6 EAP 日志显示:
并在应用程序上下文文件中使用变量:
抱歉我的英语不好
Yo should be use of this manner:
First declare the spring bean
Now in the
WEB-INF/classes
directory create the fileconfig.properties
and put this:Note: When I deploy JBoss 6 EAP the log shows me:
and use the variable in application context file:
Sorry for my bad english