PropertyPlaceholderConfigurer 在磁盘上找不到属性文件
我正在尝试将工作的 spring WAR 转移到 OSGI 环境(在 glassfish 3.1 和蓝图中,spring 3.0.5)。 应用程序从磁盘加载属性文件,如下所示:
<bean id="myProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="${my_conf}/my.properties"/>
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
</bean>
我在调试器中看到 ${my_conf}/my.properties
已转换为现有路径 (c:\conf\my.properties)
我使用在下一个 bean 声明中的 my.properties
中定义的属性 jms.url
<amq:broker useJmx="false" persistent="false" brokerName="embeddedbroker">
<amq:transportConnectors>
<amq:transportConnector uri="tcp://${jms.url}"/>
<amq:transportConnector uri="vm://embeddedbroker" />
</amq:transportConnectors>
</amq:broker>
在部署中,我收到异常 “无法解析占位符 ${jms.url}”
为什么呢失败?还有另一种方法可以从磁盘上的文件加载属性吗?
谢谢
I am trying to move a working spring WAR to OSGI environment (in glassfish 3.1 and blueprint, spring 3.0.5).
The application loads properties file from disk, like this:
<bean id="myProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="${my_conf}/my.properties"/>
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
</bean>
I see in debugger that ${my_conf}/my.properties
is translated to the existing path (c:\conf\my.properties)
I use the property jms.url
defined in my.properties
in the next bean declaration
<amq:broker useJmx="false" persistent="false" brokerName="embeddedbroker">
<amq:transportConnectors>
<amq:transportConnector uri="tcp://${jms.url}"/>
<amq:transportConnector uri="vm://embeddedbroker" />
</amq:transportConnectors>
</amq:broker>
And in deployment I get an exception "Could not resolve placeholder ${jms.url}"
Why it fails? Is there another way to load properties from file on disk?
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于它是 OSGI 环境,因此您需要将 spring-osgi-core jar 添加到您的应用程序中。查看此链接来配置属性-OSGI 框架的占位符。
Since its an OSGI environment, you will need spring-osgi-core jar added to your application. Take a look at this link to configure property-placeholder for OSGI framework.
这不是解决方案,而是对我的问题的解释。
该问题与 spring 3 和 osgi 中的错误有关。
我必须打开 spring 日志到调试级别才能理解它。
It isn't a solution, but an explanation of my problem.
The problem is related to this bug in spring 3 and osgi.
I had to open spring logs to debug level to understand it.