在Spring 3中使用<util:properties>加载多个属性文件

Ans*_*hul 8 spring spring-mvc

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

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

Ale*_*pov 21

实际上<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>
Run Code Online (Sandbox Code Playgroud)


Pio*_*zda 9

我的解决方案

<context:property-placeholder location="classpath*:*.properties,file:/some/other/path/*.properties" />
Run Code Online (Sandbox Code Playgroud)