IOC中配置的bean
<bean id="studentFive" class="com.tian.spring.pojo.Student">
<property name="sid" value="1004"></property>
<property name="sname" value="赵六"></property>
<property name="age" value="26"></property>
<property name="gender" value="男"></property>
<property name="clazz">
<!--内部bean,只能在当前bean的内部使用,不能直接通过IOC容器获取-->
<bean id="clazzInner" class="com.tian.spring.pojo.Clazz">
<property name="cid" value="2222"></property>
<property name="cname" value="远大前程班"></property>
</bean>
</property>
<property name="hobby">
<array>
<value>唱</value>
<value>跳</value>
<value>rap</value>
</array>
</property>
</bean>
<array>标签就是专为数组类型赋值准备的
如果是字面量类型数组,我们就用value标签
如果是类类型,则用ref标签
测试类:
@Test
public void testDI(){
//获取IOC容器
ApplicationContext ioc = new ClassPathXmlApplicationContext("spring-ioc.xml");
//获取bean
Student student = ioc.getBean("studentFive", Student.class);
System.out.println(student);
}
结果:
Student{sid=1004, sname='赵六', age=26, gender='男', score=null, hobby=[唱, 跳, rap], clazz=Clazz{cid=2222, cname='远大前程班'}}