Thursday, January 3, 2013

Spring - How to inject List or Map using bean?

In this example we will see how to How to inject List or Map using Spring bean. For complete setup using eclipse you can refer my previous article, Spring Hello World Example.

About the example - We have a class with two instance variables city as Map and president as List. We will set those values using Spring bean with the help of Spring configuration file  applicationContext.xml. Please see the self explanatory codes below


Output :

{United States=Washington, United Kingdom=London, China=Beijing, India=Delhi}
[Hu Jintao, Pranab Mukherjee, Barack Obama, David Cameron]