Announcement Announcement Module
Collapse
No announcement yet.
PropertyPlaceholderConfigurer - defaults don't work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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"

    Comment


    • #3
      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!

      Comment


      • #4
        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.

        Comment


        • #5
          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

          Comment

          Working...
          X