Results 1 to 2 of 2

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

  1. #1

    Question 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. #2
    Join Date
    Nov 2005
    Location
    Stockholm, Sweden
    Posts
    54

    Default

    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>
    --
    Consultant/Contractor
    Stockholm, Sweden

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •