使用集合方式注入Ioc
1.创建类
//集合 private String[] arrays; //list集合 private List<Integer> lists; //map集合 private Map<String,Object> maps; //set集合 private Set<String> sets; //properties private Properties properties;
2.编写applicationContext.xml配置文件
<bean id="diTest" class="cn.spring.entity.DiTest">
<property name="arrays">
<array>
<value>zhangsa</value>
</array>
</property>
<property name="lists"><!--为list集合赋值-->
<list>
<value>14</value>
<value>15</value>
</list>
</property>
<property name="sets"><!--为set集合赋值-->
<set>
<value>山间的风</value>
<value>张三</value>
</set>
</property>
<property name="maps"><!--为map集合赋值-->
<map>
<entry key="姓名" value="山间的风"></entry>
<entry key="年龄" value="16"></entry>
</map>
</property>
<property name="properties">
<props>
<prop key="username">山间的风</prop>
<prop key="password">123456</prop>
</props>
</property>
</bean>
3.编写测试类
ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml"); DiTest diTest = (DiTest) context.getBean("diTest"); System.out.println(diTest.getLists());