Spring自动装配模式一:no解析
2011-04-27 21:35
246 查看
Spring 自动装配
优点:自动装配能显著减少配置的数量。
Spring自动装配的5种模式:
可以使用bean元素的autowire属性来指定bean的装配模式:no、byName、byType、constructor、autodetect
Spring自动装配模式一:no解析
不使用自动装配。必须通过ref元素指定依赖,这是默认设置。由于显式指定协作者可以使配置更灵活、更清晰,因此对于较大的部署配置,推荐采用该设置。而且在某种程度上,它也是系统架构的一种文档形式。
配置文件:
<bean id="homeAddressServiceImpl"
class="cn.csdn.service.HomeAddressServiceImpl"
scope="singleton">
<property name="address">
<value>北京海淀上地软件园</value>
</property>
<!--
<constructor-arg
index="0">
<value>北京</value>
</constructor-arg>
-->
</bean>
<bean id="empServiceImpl" class="cn.csdn.service.EmpServiceImpl"
scope="singleton"
>
<property name="companyAddress" ref="homeAddressServiceImpl"></property>
</bean>
cn.csdn.service.EmpServiceImpl 代码
package cn.csdn.service;
public class EmpServiceImpl {
/**公司地址*/
private AddressServiceImpl companyAddress;
public
EmpServiceImpl(AddressServiceImpl companyAddress) {
super();
this.companyAddress = companyAddress;
}
}
优点:自动装配能显著减少配置的数量。
Spring自动装配的5种模式:
可以使用bean元素的autowire属性来指定bean的装配模式:no、byName、byType、constructor、autodetect
Spring自动装配模式一:no解析
不使用自动装配。必须通过ref元素指定依赖,这是默认设置。由于显式指定协作者可以使配置更灵活、更清晰,因此对于较大的部署配置,推荐采用该设置。而且在某种程度上,它也是系统架构的一种文档形式。
配置文件:
<bean id="homeAddressServiceImpl"
class="cn.csdn.service.HomeAddressServiceImpl"
scope="singleton">
<property name="address">
<value>北京海淀上地软件园</value>
</property>
<!--
<constructor-arg
index="0">
<value>北京</value>
</constructor-arg>
-->
</bean>
<bean id="empServiceImpl" class="cn.csdn.service.EmpServiceImpl"
scope="singleton"
>
<property name="companyAddress" ref="homeAddressServiceImpl"></property>
</bean>
cn.csdn.service.EmpServiceImpl 代码
package cn.csdn.service;
public class EmpServiceImpl {
/**公司地址*/
private AddressServiceImpl companyAddress;
public
EmpServiceImpl(AddressServiceImpl companyAddress) {
super();
this.companyAddress = companyAddress;
}
}
相关文章推荐
- Spring自动装配模式二:byName的解析
- Spring自动装配模式五:autodetect的解析
- Spring自动装配模式三:byType的解析
- Spring自动装配模式三:byType的解析
- Spring自动装配模式四:constructor的解析
- spring自动装配(No qualifying bean )
- 在 Spring 自动装配 模式下手工从IOC中获取实例
- Spring源码解析-autowiring自动装配的实现
- 【JavaEE学习笔记】Spring_02_IoC/DI依赖注入,集合对象属性注入,自动装配,代理模式
- Spring之自动装配解析
- spring中五种自动装配的区别及依赖检查模式的应用
- 通过xml文件配置 spring自动装配5中模式
- Spring自动装配解析
- Spring_ Spring_教程9_Spring中Bean的自动装配六种模式
- spring boot 源码解析40-CounterService,GaugeService默认自动装配解析
- Spring之IOC自动装配解析
- Spring中Bean自动装配的五种模式
- spring笔记——bean自动装配的5种模式(autowrite属性)
- Spring之IOC自动装配解析
- Spring的Autowired自动装配(XML版本+Annotation版本+源码+解析)