package com.h3.common;
import java.util.list;
import java.util.map;
import java.util.properties;
import java.util.set;
public class customer
{
private list<object> lists;
private set<object> sets;
private map<object, object> maps;
private properties pros;
//...
}
<property name="lists"> <list> <value>1</value> <ref bean="personbean" /> <bean class="com.h3.common.person"> <property name="name" value="h3list" /> <property name="address" value="hainan" /> <property name="age" value="28" /> </bean> </list> </property>
<property name="sets"> <set> <value>1</value> <ref bean="personbean" /> <bean class="com.h3.common.person"> <property name="name" value="h3set" /> <property name="address" value="hainan" /> <property name="age" value="28" /> </bean> </set> </property>
<property name="maps"> <map> <entry key="key 1" value="1" /> <entry key="key 2" value-ref="personbean" /> <entry key="key 3"> <bean class="com.h3.common.person"> <property name="name" value="h3map" /> <property name="address" value="hainan" /> <property name="age" value="28" /> </bean> </entry> </map> </property>
<property name="pros"> <props> <prop key="admin">admin@h3.com</prop> <prop key="support">support@h3.com</prop> </props> </property>
<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-2.5.xsd"> <bean id="customerbean" class="com.h3.common.customer"> <!-- java.util.list --> <property name="lists"> <list> <value>1</value> <ref bean="personbean" /> <bean class="com.h3.common.person"> <property name="name" value="h3list" /> <property name="address" value="hainan haikou" /> <property name="age" value="28" /> </bean> </list> </property> <!-- java.util.set --> <property name="sets"> <set> <value>1</value> <ref bean="personbean" /> <bean class="com.h3.common.person"> <property name="name" value="h3set" /> <property name="address" value="hainan haikou" /> <property name="age" value="28" /> </bean> </set> </property> <!-- java.util.map --> <property name="maps"> <map> <entry key="key 1" value="1" /> <entry key="key 2" value-ref="personbean" /> <entry key="key 3"> <bean class="com.h3.common.person"> <property name="name" value="h3map" /> <property name="address" value="hainan haikou" /> <property name="age" value="28" /> </bean> </entry> </map> </property> <!-- java.util.properties --> <property name="pros"> <props> <prop key="admin">admin@h3.com</prop> <prop key="support">support@h3.com</prop> </props> </property> </bean> <bean id="personbean" class="com.h3.common.person"> <property name="name" value="h31" /> <property name="address" value="hainan haikou 1" /> <property name="age" value="28" /> </bean> </beans>
执行程序
package com.h3.common;
import org.springframework.context.applicationcontext;
import org.springframework.context.support.classpathxmlapplicationcontext;
public class app
{
public static void main( string[] args )
{
applicationcontext context = new classpathxmlapplicationcontext("applicationcontext.xml");
customer cust = (customer)context.getbean("customerbean");
system.out.println(cust);
}
}
输出
customer [lists=[1, com.h3.common.person@4e4ee70b, com.h3.common.person@1e1867d2], sets=[1, com.h3.common.person@4e4ee70b, com.h3.common.person@52f644b4], maps={key 1=1, key 2=com.h3.common.person@4e4ee70b, key 3=com.h3.common.person@54481b6d}, pros={admin=admin@h3.com, support=support@h3.com}]