Announcement Announcement Module
Collapse
No announcement yet.
how to set property values with pre-defined property value Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to set property values with pre-defined property value

    <bean id="rootbean" class="com.test.RootBean">
    <property name="rootDir" value="rootdir"/>
    <property name="subbean">
    <bean class="com.test.SubBean">
    <property name="subDir" value="rootdir/subdir"/>
    </bean>
    </property>
    </bean>
    how to set property "subDir" with pre-defined property "rootDir".
    set subDir=rootDir+"/subdir".

  • #2
    how to set property values with pre-defined property value

    Hi,
    I think that this can be achieved indirectly by using PropertyPlaceholderConfigurer. Example:

    1. create a property file on your classpath, say 'app.properties':
    # defines the root directory
    rootDir=some/root/dir

    2. reference that file in your spring config:

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
    <property name="location">
    <value>classpath:app.properties</value>
    </property>
    </bean>

    3. use the property in your bean definition

    <bean id="rootbean" class="com.test.RootBean">
    <property name="rootDir" value="${rootDir}"/>
    <property name="subbean">
    <bean class="com.test.SubBean">
    <property name="subDir" value="${rootDir}/subdir"/>
    </bean>
    </property>
    </bean>

    See http://static.springsource.org/sprin...onfigurer.html

    Tom

    Comment

    Working...
    X