Announcement Announcement Module
Collapse
No announcement yet.
PropertyOverrideConfigurer and LIST properties Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • PropertyOverrideConfigurer and LIST properties

    I fell in love with the PropertyOverrideConfigurer. Using the following configuration it lets me have a context file that is identical between DEV, TEST and PROD servers while keeping server-specific values in a properties file for each server. I can even have all of the properties file present in my DEV box (and version control) and only the DEV one is used since the last PropertyOverrideConfigurer is the one that gets used.

    In the context:
    Code:
    <bean class="org.springframework.beans.factory.config.PropertyOverrideConfigurer" >
        <property name="locations"              value="classpath*:myAppPROD.properties" />
        <property name="ignoreResourceNotFound" value="true" />
    </bean>
    <bean class="org.springframework.beans.factory.config.PropertyOverrideConfigurer" >
        <property name="locations"              value="classpath*:myAppDEV.properties" />
        <property name="ignoreResourceNotFound" value="true" />
    </bean>
    
    <bean id="myBeanId" class="mypackage.MyClass">
        <property name="appSpecificProperty"    value="1234" />
        <property name="serverSpecificProperty" value="" />
    </bean>
    In myAppDEV.properties:
    Code:
    myBeanId.serverSpecificProperty=devhostname56.domain.com
    It works great. But... I am stumped about how to setup properties that have a list of strings as its values. For example, if I were to hard-code it in the context such a property could be defined as:

    Code:
    <bean id="myListBean" class="mypackage.MyOtherClass>
        <property name="myListProperty">
          <list>
            <value>myString1</value>
            <value>myString2</value>
            <value>myString3</value>
          <list>
        </property>
    </bean>
    I typically use list properties like the one above for email address lists that are different between DEV and PROD. And here comes the question:

    Without changing MyOtherClass, is there a way to define the list values in myAppDEV.properties and specify <property name="myListProperty"> in a way that is compatible with the PropertyOverrideConfigurer?

  • #2
    Try with SpEL #{ { '[email protected]', '[email protected]'} } or create a PropertyEditor like StringArrayPropertyEditor.

    Cheers

    Comment


    • #3
      The explanation on the SpEL web page was very clear and the solution was trivial to implement.

      Now I can have a common context file and externalize all server-specific values to server-specific properties files. Absolutely awesome.

      Thank you chelu!!!

      Comment

      Working...
      X