Announcement Announcement Module
Collapse
No announcement yet.
Set up one PropertyPlaceholderConfigurer from another Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Set up one PropertyPlaceholderConfigurer from another

    Hi,

    I'm trying to set the property of a bean used by one PropertyPlaceholderConfigurer from a system property like so:

    Code:
    <beans>
    <bean id="systemPropConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
        <property name="ignoreUnresolvablePlaceholders" value="true" />
    </bean>
    
    <bean class="org.apache.commons.configuration.DatabaseConfiguration" id="dbConfig">
        <constructor-arg>
            <bean id="propertiesDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
                <property name="database" value="${database}" />
                [other properties...]
            </bean>
        </constructor-arg>
        [other constructor-args...]
    </bean>
    
    <bean id="configureProperties" class="org.apache.commons.configuration.ConfigurationConverter"
            factory-method="getProperties">
        <constructor-arg ref="dbConfig" />
    </bean>
    
    <bean id="dbPropConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="properties" ref="configureProperties" />
        <property name="ignoreUnresolvablePlaceholders" value="false" />
    </bean>
    
    [other beans that get their properties filled in by dbPropConfig...]
    </beans>
    However, when I run

    Code:
    java -Ddatabase=mydb -jar myjar.jar
    ${database} is not expanded when dbConfig is created, and a SQLException ends up getting thrown. I've seen a number of other posts with similar issues, but haven't found a solution yet. Any ideas? I'm using Spring 2.5.4.

    Thanks,
    -Jesse

  • #2
    Have you tried setting the order property on your PropertyPlaceholderConfigurer?
    As a PropertyPlaceholderConfigurer is a BeanFactoryPostProcessor, you should be able to set the order that they run. I don't know whether this will fix your issue, but it's something worth trying.

    Comment


    • #3
      Yep, I tried setting the order, but it had no effect.

      Comment


      • #4
        Sometimes there are problems when using more than one property placeholder in the same context. Is not possible to join them in one?

        Comment


        • #5
          I don't see how I'd join them...

          Comment


          • #6
            There is a known problem in spring that does not allow (generally speaking, as there are some exceptions= usage of 2 property placeholder configurers when one of them depends (directly or indirectly) on results of other. It can not be fixed without relatively major redesign and so would not be fixed prior 3.0 (at least). You may try PropertyOverrideConfigurer instead of first PropertyPlaceholderConfigurer.

            Originally posted by jessemerriman View Post
            Hi,

            I'm trying to set the property of a bean used by one PropertyPlaceholderConfigurer from a system property like so:

            Code:
            <beans>
            <bean id="systemPropConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
                <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
                <property name="ignoreUnresolvablePlaceholders" value="true" />
            </bean>
            
            <bean class="org.apache.commons.configuration.DatabaseConfiguration" id="dbConfig">
                <constructor-arg>
                    <bean id="propertiesDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
                        <property name="database" value="${database}" />
                        [other properties...]
                    </bean>
                </constructor-arg>
                [other constructor-args...]
            </bean>
            
            <bean id="configureProperties" class="org.apache.commons.configuration.ConfigurationConverter"
                    factory-method="getProperties">
                <constructor-arg ref="dbConfig" />
            </bean>
            
            <bean id="dbPropConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
                <property name="properties" ref="configureProperties" />
                <property name="ignoreUnresolvablePlaceholders" value="false" />
            </bean>
            
            [other beans that get their properties filled in by dbPropConfig...]
            </beans>
            However, when I run

            Code:
            java -Ddatabase=mydb -jar myjar.jar
            ${database} is not expanded when dbConfig is created, and a SQLException ends up getting thrown. I've seen a number of other posts with similar issues, but haven't found a solution yet. Any ideas? I'm using Spring 2.5.4.

            Thanks,
            -Jesse

            Comment


            • #7
              I don't know if a PropertyOverrideConfigurer would be able to use system properties, but I got it to work by using Alex Wei's EagerPropertyPlaceholderConfigurer for the first configurer:

              http://jira.springframework.org/secu...onfigurer.java

              Comment

              Working...
              X