【问题标题】:context:property-placeholder not working for multiple files上下文:属性占位符不适用于多个文件
【发布时间】:2013-01-05 13:35:51
【问题描述】:

我有 2 个属性文件。我已经提到了context:property-placeholder 中的两个文件,就像这样......

<context:property-placeholder location="conf/ConfServer.conf,conf/LicenseSettings.properties" />

这个我也试过了

<context:property-placeholder location="conf/ConfServer.conf,conf/LicenseSettings.properties" />

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>conf/LicenseSettings.properties</value>
        </list>
    </property>
   <property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>

我尝试过的上述两种方法都不起作用。
谁能发现错误并帮助我解决这个问题?
我已经提到了this,但对我来说效果不佳。

【问题讨论】:

  • 你能单独加载它们吗?

标签: java spring spring-mvc


【解决方案1】:

您可以尝试从项目根目录中引用这些属性

conf/ConfServer.conf

conf/LicenseSettings.properties

这些可能没有正确引用。

【讨论】:

    【解决方案2】:

    您可以在配置文件中指定多个context:property-placeholder 标签。您还可以使用order 属性指定首先加载哪个。

    <context:property-placeholder location="conf/ConfServer.conf" order="1" ignore-unresolvable="true" />
    <context:property-placeholder location="conf/LicenseSettings.properties" order="2" ignore-unresolvable="true" />
    

    【讨论】:

    • 非常感谢。在尝试这个时,结果是一样的。 conf/ConfServer.conf 运行良好,但不是第二个文件。你想让我贴出我用来初始化从文件中读取的变量的代码吗?
    • 对不起,我错了,你的方法效果很好。非常感谢。我花了大约 2 个小时来解决这个问题。再次感谢您。
    • @Freakyuser 很高兴我能帮上忙
    • 使用 Spring 4.1.5,我只成功地使用了一个 context:property-placeholder 标签,但是“location”属性接受多个逗号分隔的位置。参见例如stackoverflow.com/a/3407752/218139
    • 我遇到了同样的问题,ignore-unresolvable="true" 解决了我的问题。
    猜你喜欢
    • 2013-05-29
    • 2017-02-20
    • 1970-01-01
    • 1970-01-01
    • 2013-12-06
    • 1970-01-01
    • 1970-01-01
    • 2012-08-03
    • 2015-09-15
    相关资源
    最近更新 更多