10

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Anshul
  • 635
  • 2
  • 11
  • 27

3 Answers3

24

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>
Alexei Osipov
  • 728
  • 10
  • 17
10

My solution

<context:property-placeholder location="classpath*:*.properties,file:/some/other/path/*.properties" />
Piotr Gwiazda
  • 12,080
  • 13
  • 60
  • 91
  • This works for the placeholder that you have in your config file ${some.props}, but that does not work with @Value("#{properties}") in your bean, to use that solution that @Alexei Osipov works, just in case someone need that information – Koitoer Oct 09 '14 at 18:08
3

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

Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327