Results 1 to 5 of 5

Thread: PropertyPlaceholderConfigurer - defaults don't work

  1. #1
    Join Date
    Sep 2005
    Posts
    7

    Default PropertyPlaceholderConfigurer - defaults don't work

    Hi!

    I was trying to use the following configuration:

    Code:
    <bean name="PropertyPlaceholderConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
        <property name="properties">
            <props>
                <prop key="msx.db">hsqldb</prop>
            </props>
        </property>
        <property name="locations">
            <list>
                <value>classpath&#58;local.properties</value>
                <value>classpath&#58;$&#123;msx.db&#125;.properties</value>
            </list>
        </property>
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
    </bean>
    It works perfectly if I set the system property msx.db. If I don't set it, it seems to disregard the <property name="properties">...</property> part, which is supposed to be the "default" properties.

    Any idea why?

  2. #2
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    Hmm, from the javadoc and the source it would appear that it should use the property defined in "msx.db" unless there is a system property set.

    Can you abstract this into a test case? Making *doubly* sure that there isn't an empty system property called "msx.db"

  3. #3
    Join Date
    Sep 2005
    Posts
    7

    Default

    I tried starting an ClassPathXmlApplicationContext with just this bean definition, and it didn't work with the same error: FileNotFoundException - cannot find ${msx.db}.properties. Commeted out the line that refered to the file, and listed the SystemProperties. "msx.db" wasn't there.

    Again, when running the test with the "msx.db" property set to something meaningful - everything works just fine.

    I think I know why it's happening: in order to fallback to the defaults specified in the "properties" property, it needs to make sure this property doesn't exit in the file(s). So it tries to load the files, but in order to resolve the name of the file, it needs to do the substituton. But it can't, since before falling back to the defaults.... etc.

    This brings another question - is it possible to define two PropertyPlaceholderConfigurer beans, and how will they work with each other?

    Thanks!

  4. #4
    Join Date
    Sep 2005
    Posts
    7

    Default

    Tried having two PropertyPlaceholderConfigurer beans configured:
    Code:
    <bean name="PropertyPlaceholderConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
        <property name="order" value="0"/>
        <property name="locations">
            <list>
                <value>classpath&#58;local.properties</value>
            </list>
        </property>
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
    </bean>
    
    <bean name="PropertyPlaceholderConfigurer2"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
        <property name="properties">
            <props>
                <prop key="msx.db">hsqldb</prop>
            </props>
        </property>
        <property name="order" value="1"/>
        <property name="locations">
            <list>
                <value>classpath*&#58;$&#123;msx.db&#125;.properties</value> 
            </list>
        </property>
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
    </bean>
    msx.db is defined inside local.properties.

    Still no luck, Spring complains about not finding ${msx.db}.properties on the classpath.

  5. #5
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    Man, I really must learn to read the entire message before jumping in

    Yes, of course you are getting the chicken and egg problem.

    Don't really know how you would solve this to be honest. You could look at replacing the variable outside of spring, i.e. through ant token substitution.

    Sorry

Similar Threads

  1. Replies: 1
    Last Post: Aug 1st, 2005, 01:52 AM
  2. Channel and message transformation question
    By Alarmnummer in forum Architecture
    Replies: 12
    Last Post: May 11th, 2005, 05:06 PM
  3. Replies: 3
    Last Post: Dec 22nd, 2004, 02:30 PM
  4. Spring can't work on Eclipse
    By ryanhowai in forum Architecture
    Replies: 1
    Last Post: Nov 9th, 2004, 06:50 AM
  5. Replies: 2
    Last Post: Sep 7th, 2004, 07:02 AM

Posting Permissions

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