The Spring IoC container also supports dependency injection by setter method, which is the preferred method of dependency injection in Spring. The property subelement of bean is used for setter injection.

  • applicationContext.xml

    The Students bean class has three attributes like age, name and city. All the three attributes are set thru its setters and getters and a method to show() disply these informations.


    We are providing the information into the bean by this file. The property element invokes the setter method. The value subelement of property will assign the specified value.

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


    Age:20 Name:Smith City:Australia

    Leave a Reply

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