Inheritance in Spring


This is 11 of 16 parts of spring tutorial series: Inheritance in Spring.

Tutorial Content: Spring tutorial for beginners

In spring,inheritance is supported for reusing already written bean,so that beans can share common attributes and methods among them.

child bean will have all attributes and methods of parent bean,also child bean can override parent bean’s attributes or methods.

For configuring spring in your eclipse ide please refer  hello world example

Inheritance in Spring example

This is simple pojo class having some attributes so here preson has name .
Create under package org.arpit.javapostsforlearning.Copy following content into

This is also simple pojo class having one attribute called “employeeNumber”.

Create under package following content into


Here We have declared two beans with corresponding ids.
1.Class Person with id as “PersonBean”
2.Class Employee with id as “EmployeeBean”
We have used  parent property of to show that Person is parent class of Employee.

This class contains main function.Create under package org.arpit.javapostsforlearning.Copy following content into
You can note here that we have used ClassPathXmlApplicationContext for getting bean here.There are various ways for getting beans.In hello world example we have used XmlBeanFactory for getting beans.

5.Run it

When you will run above application,you will get following as output.

That’s all about Inheritance in Spring.
In next post,we will see spring applicationContext.


Add Comment