Alex Rivera | Logout

Spring's overriding bean

Asked 2011-05-01T15:08:41.333
43

Can we have duplicate names for the same bean id that is mentioned in the XML? If not, then how do we override the bean in Spring?

Edit
Report

1 Answer

9

An example from official spring manual:

<bean id="inheritedTestBean" abstract="true"
    class="org.springframework.beans.TestBean">
  <property name="name" value="parent"/>
  <property name="age" value="1"/>
</bean>

<bean id="inheritsWithDifferentClass"
      class="org.springframework.beans.DerivedTestBean"
      parent="inheritedTestBean" init-method="initialize">
  <property name="name" value="override"/>
  <!-- the age property value of 1 will be inherited from  parent -->
</bean>

Is that what you was looking for? Updated link

answered 2011-05-01T15:38:40.180

Your Answer