spring的两种注入方式
2013-10-07 10:24
267 查看
1、利用属性注入:基本类型用"value",引用类型用"ref"
<bean id="persondDao" class="dao.impl.PersonDao"/>
<bean id="personService" class="service.Personservice"/>
<property name="personDao" ref="persondDao"/>
</bean>
2、利用构造函数注入:基本类型时"type"属性值可以省略
<bean id="persondDao" class="dao.impl.PersonDao"/>
<bean id="personService" class="service.Personservice"/>
<constructor-arg index="0" type="dao.impl.PersonDao" ref="persondDao"/>
</bean>
<bean id="persondDao" class="dao.impl.PersonDao"/>
<bean id="personService" class="service.Personservice"/>
<property name="personDao" ref="persondDao"/>
</bean>
2、利用构造函数注入:基本类型时"type"属性值可以省略
<bean id="persondDao" class="dao.impl.PersonDao"/>
<bean id="personService" class="service.Personservice"/>
<constructor-arg index="0" type="dao.impl.PersonDao" ref="persondDao"/>
</bean>
相关文章推荐
- map集合遍历的两种方式,在spring中的依赖注入
- 那些年、一起追过的Spring--(2)----IOC、两种依赖注入方式
- Spring的两种依赖注入方式:setter方法注入与构造方法注入 以及两种方式的区别!
- Spring属性注入的两种方式
- Spring-2:bean的两种依赖注入方式
- spring学习笔记(4)——spring的两种注入方式
- 3.Spring Boot + Security初步使用(覆盖配置的两种方式 配置类和XML注入以自定义页面为例)
- spring的两种属性注入方式setter注入和构造器注入或者自动注入
- Spring的两种依赖注入方式:setter方法注入与构造方法注入
- Spring的两种注入方式
- Spring的两种依赖注入方式:setter方法注入与构造方法注入
- spring依赖注入的两种方式
- Spring 单例模式的两种注入方式
- Spring依赖注入常用的两种方式
- Spring属性注入的两种方式
- Spring依赖注入的两种方式(根据实例详解)
- Spring的两种常见的注入方式 构造方法注入以及setter方法注入
- Spring两种注入方式的区别
- spring_01<bean>的两种注入方式
- spring注入bean两种方式(属性注入,构造器注入)