【问题标题】:PropertyPlaceholderConfigurer does not find property file on diskPropertyPlaceholderConfigurer 在磁盘上找不到属性文件
【发布时间】:2012-02-05 16:16:09
【问题描述】:

我正在尝试将工作的 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>

在部署中我得到一个异常"Could not resolve placeholder ${jms.url}"

为什么会失败?还有其他方法可以从磁盘上的文件中加载属性吗?

谢谢

【问题讨论】:

  • 可能重复 question。您在调试器中看到的可能由另一个 applicationContext.xml 中的另一个 bean 加载
  • 谢谢。我尝试将位置路径设置为不存在的文件,但没有出现异常。我试图设置属性文件的硬编码路径,但没有任何改变。请记住,它在非 osgi 战争中有效

标签: spring osgi blueprint


【解决方案1】:

由于它是一个 OSGI 环境,您需要将 spring-osgi-core jar 添加到您的应用程序中。看看这个link 为 OSGI 框架配置属性占位符。

【讨论】:

  • 谢谢。根据这篇文章:osgi-spring-config,我认为我不必使用 osgix:cm-properties。我错了吗?
  • 如果您不使用 spring-osgi-core,您将无法在 context.xml 中使用 osgix 标签,因为这些标签的架构位于 spring-osgi-core 中
  • 同时我没有使用osgix标签,我只使用bean和amq。我正在使用 spring-osgi-core jar 和许多其他 spring jar,但它并不能帮助我解决所描述的问题
【解决方案2】:

这不是解决方案,而是对我的问题的解释。 问题与此bug in spring 3 and osgi 有关。

我必须打开 spring 日志来调试级别才能理解它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-06
    • 2020-01-31
    • 1970-01-01
    • 2015-10-13
    • 2021-01-26
    • 1970-01-01
    • 2016-02-20
    • 2013-06-30
    相关资源
    最近更新 更多