PropertyPlaceholderConfigurer 在磁盘上找不到属性文件

发布于 2025-01-02 10:50:39 字数 1012 浏览 6 评论 0原文

我正在尝试将工作的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

这样的小城市 2025-01-09 10:50:39

由于它是 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.

扎心 2025-01-09 10:50:39

这不是解决方案,而是对我的问题的解释。
该问题与 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文