要点
<bean id="h" class="dd.H">
<property name="mList">
<list>
<value>INDIA</value>
<value>Pakistan</value>
<value>USA</value>
<value>USA</value>
</list>
</property>
</bean>
package dd;
import java.util.*;
public class H {
List mList;
public List getmList() {
System.out.println("List mList :" + mList);
return mList;
}
public void setmList(List mList) {
this.mList = mList;
}
}
package dd;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class T {
public static void main(String[] args) {
// Spring 注入集合
System.out.println("Spring 注入集合");
H h = (H)context.getBean("h");
h.getmList();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="h" class="dd.H">
<property name="mList">
<list>
<value>INDIA</value>
<value>Pakistan</value>
<value>USA</value>
<value>USA</value>
</list>
</property>
</bean>
</beans>