0

Is that possible to define at Spring XML context few beans with the same property set?

Example

<bean id="bean1" class="com.my.company.model.MyProcedureBean">
    <property name="name" value="val1"/>
    <property name="pre">
        <list>
            <ref bean="Y00"/>
            <ref bean="YNT"/>
            <ref bean="YAB"/>
        </list>
    </property>
    <property name="post">
        <list>
                <ref bean="YIO"/>
                <ref bean="YC1"/>
        </list>
    </property>
    <property name="plain">
        <list>
            <ref bean="YA3"/>
            <ref bean="YP4"/>
            <ref bean="YA5"/>
        </list>
    </property>
</bean>

<bean id="bean2" class="com.my.company.model.MyProcedureBean">
  // DO NOT WANT TO DUPLICATE ALL PROPERTIES HERE AS AT **bean1**
</bean>
Michael Z
  • 3,883
  • 10
  • 43
  • 57

1 Answers1

3

Set the Abstract property of a bean to true and then defin other bean with parent property equal to the abstract bean! like this

<bean id="parentBean" class="xxx" abstract="true">
    <property name="..." value="..." />
    <property name="..." value="..." />
    <property name="..." value="..." />
</bean>

<bean id="bean1" parent="parentBean">

</bean>
<bean id="bean2" parent="parentBean">

</bean>
Morteza Adi
  • 2,413
  • 2
  • 22
  • 37