Spring Setter Injection with Collection

We can inject collection values by setter method in spring framework. There can be used three elements inside the property element.

It can be:

  • list
  • set
  • map

In this example, we are using list that can have duplicate elements, set that have only unique elements and map that have both key and value.


This class contains List,Set,Map and Properties with setters and getters method that prints the information.


Following is the configuration file applicationContext.xml which has configuration for all the type of collections.


This class gets the bean from the applicationContext.xml file.


List Elements :[INDIA, Australia, USA, USA] Set Elements :[INDIA, Australia, USA] Map Elements :{1=INDIA, 2=Australia, 3=USA, 4=USA} Properties Elements :{two=Australia, one=INDIA, three=USA, four=USA}

Leave a Reply

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