Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load multiple properties file using <util:properties> in spring 3

I want to load multiple properties files using <util:properties> tag in a spring 3 application. I searched on the blogs, but cannot get the correct path to do this.

Hopefully somebody give me the answer to overcome this problem.

like image 222
Anshul Avatar asked Dec 19 '11 09:12

Anshul


3 Answers

Actually <util:properties> is just convenient tag for org.springframework.beans.factory.config.PropertiesFactoryBean. And PropertiesFactoryBean does support multiple locations.

So it is possible to create bean with Properties this way:

    <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>
like image 193
Alexei Osipov Avatar answered Nov 12 '22 08:11

Alexei Osipov


My solution

<context:property-placeholder location="classpath*:*.properties,file:/some/other/path/*.properties" />
like image 26
Piotr Gwiazda Avatar answered Nov 12 '22 08:11

Piotr Gwiazda


util:properties seems to support only 1 properties file (reference). You might want to use the configuration suggested by @peperg.

like image 3
Aravind Yarram Avatar answered Nov 12 '22 08:11

Aravind Yarram