Announcement Announcement Module
Collapse
No announcement yet.
replace properties from file found in classpath or either set via system.properties Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • replace properties from file found in classpath or either set via system.properties

    Hi,

    my AppContext.xml file need some configuration I want to provide in an external .properties file:

    <bean id="myBean" class="myClass" >
    <property name="password" value="${pwd}"/>
    </bean>

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
    <property name="locations">
    <list>
    <value>file:${external.properties}</value>
    <value>classpath:default.properties</value>
    </list>
    </property>
    <property name="ignoreResourceNotFound" value="true"/>
    <property name="ignoreUnresolvablePlaceholders" value = "true"/>
    </bean>


    How can I configure the PropertyPlaceholderConfigurer to
    1st check if the system property "external.properties" is set and than pick up this file and take the values from there
    2nd try to read default.properties from classpath

    Do I need to subclass PropertyPlaceholderConfigurer to implement this special behaviour? I guess there´s a recommended way to solve this.

    thanx in advance,

    Torsten

  • #2
    I use something like this:


    Code:
       <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
            <property name="searchSystemEnvironment" value="true"/>
            <property name="ignoreResourceNotFound" value="true"/>
            <property name="ignoreUnresolvablePlaceholders" value="true"/>
            <property name="locations">
                <list>
                    <value>classpath*:/xxx_application.properties</value>
                    <value>classpath*:/xxx_jdbc.properties</value>
                    <value>file:////etc/xxx_core.properties</value>
                </list>
            </property>
        </bean>

    Comment

    Working...
    X