spring bean 方法1:
<bean id="stu1" class="aa.xxx.chapter01.Student"> <constructor-arg index="0" value="1"/> <constructor-arg index="1" value="小明"/> </bean> <bean id="stu2" class="aa.xxx.chapter01.Student"> <property name="id" value="2"/> <property name="name" value="小张"/> <property name="interets"> <list> <value>足球</value> <value>篮球</value> <value>羽毛球</value> </list> </property> </bean> <bean id="stu3" class="aa.xxx.chapter01.Student" p:id="3" p:name="小李"/> <bean id="teacher" class="aa.xxx.chapter01.Teacher"> <property name="id" value="1"/> <property name="name" value="老师"/> <property name="students"> <list> <!-- <value>stu1</value> <value>stu2</value> <value>stu3</value> --> <ref bean="stu1"/> <ref bean="stu2"/> <ref bean="stu3"/> </list> </property> <property name="titles"> <array> <value>zuijia</value> <value>laoshi</value> </array> </property> <property name="subjects"> <map> <entry key="yuwen" value="zuijia"/> <entry key="shuxue" value="zuijia1"/> </map> </property> </bean> public class Teacher { private int id; private String name; private List<Student> students; private String[] titles; private Map<String, String> subjects; ... } public class Student { private int id; private String name; private List<String> interets; ... }方法2:
@Component(value="beanB") 同时在xml中要添加 <context:annotation-config/> <context:component-scan base-package="aa.xxx.annotation"> <!-- <context:exclude-filter type="annotation" expression="xx.packB"/> --> <!-- <context:exclude-filter type="regex" expression="xx.packB.BeanB"/> --> <context:exclude-filter type="assignable" expression="xx.packB.BeanB"/> </context>类似代码可见: http://download.csdn.net/detail/fengshunui/9777056
