Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

property-placeholder location from another property

Tags:

java

spring

I need to load some properties into a Spring context from a location that I don't know until the program runs.

So I thought that if I had a PropertyPlaceholderConfigurer with no locations it would read in my.location from the system properties and then I could use that location in a context:property-placeholder

Like this

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>    
<context:property-placeholder location="${my.location}"/>

but this doesn't work and nor does location="classpath:${my.location}"

Paul

like image 396
Paul McKenzie Avatar asked Aug 21 '09 11:08

Paul McKenzie


1 Answers

You can do this with a slightly different approach. Here is how we configure it. I load default properties and then overrided them with properties from a configurable location. This works very well for me.

<bean id="propertyPlaceholderConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
        <property name="locations">
            <list>
                <value>classpath:site/properties/default/placeholder.properties
                </value>
                <value>classpath:site/properties/${env.name}/placeholder.properties
                </value>
            </list>
        </property>
    </bean>
like image 88
Pablojim Avatar answered Oct 13 '22 08:10

Pablojim