【问题标题】:Load multiple properties file using <util:properties> in spring 3在 Spring 3 中使用 <util:properties> 加载多个属性文件
【发布时间】:2012-01-23 10:53:21
【问题描述】:

我想在 spring 3 应用程序中使用 &lt;util:properties&gt; 标签加载多个属性文件。 我在博客上搜索过,但找不到正确的路径。

希望有人能给我解决这个问题的答案。

【问题讨论】:

    标签: spring spring-mvc


    【解决方案1】:

    实际上&lt;util:properties&gt; 只是org.springframework.beans.factory.config.PropertiesFactoryBean 的方便标记。而PropertiesFactoryBean 确实支持多个位置。

    因此可以通过这种方式使用Properties 创建bean:

        <bean id="myProps" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
            <property name="locations">
                <list>
                    <value>classpath:myprops-common.properties</value>
                    <value>classpath:myprops-override.properties</value>
                    <value>classpath:some-more-props-here.properties</value>
                </list>
            </property>
        </bean>
    

    【讨论】:

      【解决方案2】:

      我的解决方案

      <context:property-placeholder location="classpath*:*.properties,file:/some/other/path/*.properties" />
      

      【讨论】:

      • 这适用于配置文件 ${some.props} 中的占位符,但不适用于 bean 中的 @Value("#{properties}") 来使用它@Alexei Osipov 有效的解决方案,以防万一有人需要该信息
      【解决方案3】:

      util:properties 似乎只支持 1 个属性文件 (reference)。您可能想要使用@peperg 建议的配置。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-08-01
        • 1970-01-01
        • 2019-03-30
        • 2016-06-18
        • 2016-07-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多