Skip to content

Instantly share code, notes, and snippets.

@madan712
Created January 3, 2013 15:20
Show Gist options
  • Save madan712/4444241 to your computer and use it in GitHub Desktop.
Save madan712/4444241 to your computer and use it in GitHub Desktop.
Spring - How to inject List/ Map using bean? We have a class Country.java with two instance variables city and president. We will set those values using applicationContext.xml.
package com.javaxp;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SpringMain {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
Country country = (Country) context.getBean("country");
System.out.println(country.getCity());
System.out.println(country.getPresident());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment