Set List Map
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd"> <context:annotation-config /> <beans> <bean class="Factory"> <constructor-arg ref="bus"></constructor-arg> </bean> <bean id="bus" class="Bus"> <constructor-arg> <set> <ref bean="person1" /> <ref bean="person2" /> </set> </constructor-arg> </bean> <bean id="person1" class="Person"> <constructor-arg value="xiaoming"></constructor-arg> </bean> <bean id="person2" class="Person"> <constructor-arg value="xiaohong"></constructor-arg> </bean> </beans> </beans>
import java.util.Set; public class Factory { private Bus bus; public Factory() { } public Factory(Bus bus) { this.bus = bus; } public Bus getBus() { return bus; } } class Bus { private Set<Person> persons; public Bus() { } public Bus(Set<Person> persons) { this.persons = persons; } public Set<Person> getPersons() { return persons; } } class Person { private String name; public Person() { } public Person(String name) { this.name = name; } public String getName() { return name; } }