A bean definition can contain a lot of configuration information, including constructor arguments, property values, and Co Ntainer-specific information such as initialization method, static factory method name, and so on.
A child bean definition inherits the configuration data from a parent definition. The child definition can override some values, or add others, as needed.
Spring Bean definition inheritance have nothing to do with Java class inheritance but the inheritance concept is same. You can define a parent bean definition as a template and other child beans can inherit the required configuration from th E Parent Bean.
When you use xml-based configuration metadata, you indicate a child bean definition by using the parent attribute , specifying the parent bean as the value of this attribute.
<?XML version = "1.0" encoding = "UTF-8"?><Beansxmlns= "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-3.0.xsd "> <BeanID= "Beanteamplate"Abstract= "true"> < Propertyname= "Message1"value= "Hello world!"/> < Propertyname= "Message2"value= "Hello Second world!"/> < Propertyname= "Message3"value= "Namaste india!"/> </Bean> <BeanID= "Helloindia"class= "Com.tutorialspoint.HelloIndia"Parent= "Beanteamplate"> < Propertyname= "Message1"value= "Hello india!"/> < Propertyname= "Message3"value= "Namaste india!"/> </Bean> </Beans>
View Code
Spring-bean Definition Inheritance