Announcement Announcement Module
Collapse
No announcement yet.
default value to be overriden by application configuration Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • default value to be overriden by application configuration

    I am trying to achieve the following use case:

    * Each configuration for a module is located in a default location (e.g. META-INF/foo/project-core-beans.xml)
    * If the configuration needs external settings, a default value is provided
    * The application configuration can override some of these settings if the defaulting does not work (quite handy if defaulting works).

    So far I have this for my project-core-beans.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
    
         <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="locations">
                <list>
                    <value>classpath:/com/foo/project-core-config.properties</value>
                </list>
            </property>
            <property name="ignoreUnresolvablePlaceholders" value="true"/>
        </bean>
        
        <bean name="fooManager" class="com.foo.FooManagerImpl">
            <property name="dataSource" ref="dataSource"/>
            <property name="incrementer" ref="stagingItemIncrementer"/>
        </bean>
    
        <bean id="stagingItemIncrementer" parent="incrementerParent">
            <property name="incrementerName" value="STAGING_ITEM_SEQ"/>
        </bean>
    
        <!-- Structure to define the right incrementer based on the target database -->
        <bean id="sequenceIncrementerParent" class="${batch.database.incrementer.class}" abstract="true">
            <property name="dataSource" ref="dataSource"/>
        </bean>
    
        <bean id="columnIncrementerParent" class="${batch.database.incrementer.class}" abstract="true"
              parent="sequenceIncrementerParent">
            <property name="columnName" value="OBJECTID"/>
        </bean>
    
        <bean id="incrementerParent" parent="${batch.database.incrementer.parent}">
            <property name="incrementerName" value="DUMMY"/>
        </bean>
    </beans>
    In com/foo/project-core-config.properties I have this

    Code:
    batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.H2SequenceMaxValueIncrementer
    batch.database.incrementer.parent=sequenceIncrementerParent
    The idea is that if I start the component without any config, it starts up with H2. but if in my main _applicationContext.xml_ I can do something like:

    Code:
    <context:property-placeholder location="classpath:/batch-mysql.properties"/>
    and use the same config with explicit config (and not the default values anymore)

    how can I achieve this? I am using 2.5.6

  • #2
    Is there something obvious that I'm missing?

    Comment


    • #3
      Hi,

      You could use PropertyOverrideConfigurer for your above requirement wherein you could provide some defautl values at the start and then replace those values with an explicit Property files.

      Refer to PropertyOverrideConfigurer API DOC for the same.

      Hope it resolves your problem.

      -Kartik

      Comment


      • #4
        Hi,

        You could use PropertyOverrideConfigurer for your above requirement wherein you could provide some defautl values at the start and then replace those values with an explicit Property files.

        Refer to PropertyOverrideConfigurer API DOC for the same.

        Hope it resolves your problem.

        -Kartik

        Comment

        Working...
        X