使用spring 3中的<util:properties> </util:properties>加载多个属性文件

时间:2011-12-19 09:12:40

标签: spring spring-mvc

我想在spring 3应用程序中使用<util:properties>标记加载多个属性文件。 我在博客上搜索过,但无法找到正确的路径。

希望有人能给我答案来克服这个问题。

3 个答案:

答案 0 :(得分:16)

实际上<util:properties>只是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>

答案 1 :(得分:9)

我的解决方案

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

答案 2 :(得分:3)

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