We can inject dependency of another class object into current bean using setter injection.In such case, we use property element. Here, our scenario is Employee HAS-A Address. The Address class object will be termed as the dependent object. Let’s see the Address class first:


This class contains four properties, setters and getters and toString() method.


It contains three properties id, name and address(dependent object) , setters and getters with display() method.


The ref attribute of property elements is used to define the reference of another bean.


This class gets the bean from the applicationContext.xml file and calls the display() method.


ID:11 Name:Smith John Student Address:51,Broadway CANBERRA WEST BEACH Australia

Leave a Reply

Your email address will not be published. Required fields are marked *