Spring 自学系列之IOC-7【collection集合注入】
2018-03-18 21:13
405 查看
spring注入bean的时候可以为集合赋值,诸如list、map、set等,但是很少用到,了解即可。<?xml version="1.0" encoding="UTF-8"?>
<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 name="userDAO" class="com.bjsxt.dao.impl.UserDAOImpl">
<property name="sets">
<set>
<value>1</value>
<value>2</value>
</set>
</property>
<property name="lists">
<list>
<value>1</value>
<value>2</value>
<value>3</value>
</list>
</property>
<property name="maps">
<map>
<entry key="1" value="1"></entry>
<entry key="2" value="2"></entry>
<entry key="3" value="3"></entry>
<entry key="4" value="4"></entry>
</map>
</property>
</bean>
<bean id="userService" class="com.bjsxt.service.UserService">
<!--
<property name="userDAO">
<ref bean="userDAO"/>
</property>
-->
<constructor-arg>
<ref bean="userDAO"/>
</constructor-arg>
</bean>
</beans>
<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 name="userDAO" class="com.bjsxt.dao.impl.UserDAOImpl">
<property name="sets">
<set>
<value>1</value>
<value>2</value>
</set>
</property>
<property name="lists">
<list>
<value>1</value>
<value>2</value>
<value>3</value>
</list>
</property>
<property name="maps">
<map>
<entry key="1" value="1"></entry>
<entry key="2" value="2"></entry>
<entry key="3" value="3"></entry>
<entry key="4" value="4"></entry>
</map>
</property>
</bean>
<bean id="userService" class="com.bjsxt.service.UserService">
<!--
<property name="userDAO">
<ref bean="userDAO"/>
</property>
-->
<constructor-arg>
<ref bean="userDAO"/>
</constructor-arg>
</bean>
</beans>
相关文章推荐
- Spring 自学系列之IOC-3 【注入类型】
- Spring 自学系列之IOC-5【简单属性的注入】
- Ioc容器依赖注入-Spring 源码系列(2)
- Spring系列之-Spring IOC容器设计:依赖注入设计
- Spring入门Blog[二、Ioc控制反转集合注入和Scope]
- Spring 自学系列之IOC-4 【bean的标识id VS name】
- Spring 自学系列之IOC-11【@Resource】
- Spring系列【08】为JavaBean的集合对象注入属性值
- Spring 自学系列之IOC-6【scope属性 b) singleton VS proptotype 】
- Spring应用、原理以及粗读源码系列(一)--框架总述、以Bean为核心的机制(IoC容器初始化以及依赖注入)
- 【SSH系列】深入浅出spring IOC中三种依赖注入方式
- Spring系列之四——Spring IOC依赖注入
- 【SSH系列】深入浅出spring IOC中三种依赖注入方式
- Spring系列之四——Spring IOC依赖注入
- Spring 自学系列之IOC-8【自动装配autowire】
- Spring 自学系列之IOC-1
- Spring的DI(Ioc) - 注入集合类型
- Spring入门Blog[二、Ioc控制反转集合注入和Scope]
- SpringIoC之集合注入与空值注入
- Spring 自学系列之IOC-2