[Spring开发笔记]Spring中自动装配详解(协作者关系)
2011-05-29 09:07
1086 查看
<!--
一、autowire="no"
表示不自动装配
二、自动根据Name进行装配,
1)要注入的bean的名称要和 被注入的类中定义的setXXX 的名字一样
<bean id="greetingServiceImpl" class="cn.csdn.service.GreetingServiceImpl" autowire="byName">
<property name="sayContent" value="大家好才是真的号!"/>
</bean>
<bean id="bs" class="cn.csdn.service.ByeService"/>
-->
<!--
三、 根据类型自动装配 autowire="byType"
1)在被注入的类中定义的setXXX 方法 的 XXX类型在配置文件中有定义(有bean定义)
2)当且仅当 XXX类型 的bean在配置文件中出现一次的时候,才能被注入
<bean id="greetingServiceImpl" class="cn.csdn.service.GreetingServiceImpl" autowire="byType">
<property name="sayContent" value="大家好才是真的号!"/>
</bean>
<bean id="bs" class="cn.csdn.service.ByeService"/>
-->
<!--
四、 根据构造方法完成自动装配 autowire="constructor"
1)在被注入的类中定义构造方法,并且参数中需要注入的类对象 ,在配置文件中有定义,
则当我们设置 bean的属性为autowire="constructor"的时候会自动装配
2)自动装配只是针对bean的操作
<bean id="greetingServiceImpl" class="cn.csdn.service.GreetingServiceImpl" autowire="constructor">
<constructor-arg index="0" value="Hello World!"/>
</bean>
<bean id="bs" class="cn.csdn.service.ByeService"/>
-->
<!--
五、根据需要自动装配, autowire="autodetect"
1)如果有默认的构造方法,则必须以set注入,根据byType模式自动装配
2)如果没有默认方法,则是采用构造器注入的。
-->
<bean id="greetingServiceImpl" class="cn.csdn.service.GreetingServiceImpl" autowire="autodetect">
<constructor-arg index="0" value="Hello World!"/>
</bean>
<bean id="bs" class="cn.csdn.service.ByeService"/>
[原创地址] [源码下载] [更多原创,多多支持多]
一、autowire="no"
表示不自动装配
二、自动根据Name进行装配,
1)要注入的bean的名称要和 被注入的类中定义的setXXX 的名字一样
<bean id="greetingServiceImpl" class="cn.csdn.service.GreetingServiceImpl" autowire="byName">
<property name="sayContent" value="大家好才是真的号!"/>
</bean>
<bean id="bs" class="cn.csdn.service.ByeService"/>
-->
<!--
三、 根据类型自动装配 autowire="byType"
1)在被注入的类中定义的setXXX 方法 的 XXX类型在配置文件中有定义(有bean定义)
2)当且仅当 XXX类型 的bean在配置文件中出现一次的时候,才能被注入
<bean id="greetingServiceImpl" class="cn.csdn.service.GreetingServiceImpl" autowire="byType">
<property name="sayContent" value="大家好才是真的号!"/>
</bean>
<bean id="bs" class="cn.csdn.service.ByeService"/>
-->
<!--
四、 根据构造方法完成自动装配 autowire="constructor"
1)在被注入的类中定义构造方法,并且参数中需要注入的类对象 ,在配置文件中有定义,
则当我们设置 bean的属性为autowire="constructor"的时候会自动装配
2)自动装配只是针对bean的操作
<bean id="greetingServiceImpl" class="cn.csdn.service.GreetingServiceImpl" autowire="constructor">
<constructor-arg index="0" value="Hello World!"/>
</bean>
<bean id="bs" class="cn.csdn.service.ByeService"/>
-->
<!--
五、根据需要自动装配, autowire="autodetect"
1)如果有默认的构造方法,则必须以set注入,根据byType模式自动装配
2)如果没有默认方法,则是采用构造器注入的。
-->
<bean id="greetingServiceImpl" class="cn.csdn.service.GreetingServiceImpl" autowire="autodetect">
<constructor-arg index="0" value="Hello World!"/>
</bean>
<bean id="bs" class="cn.csdn.service.ByeService"/>
[原创地址] [源码下载] [更多原创,多多支持多]
相关文章推荐
- [原创]java WEB学习笔记99:Spring学习---Spring Bean配置:自动装配,配置bean之间的关系(继承/依赖),bean的作用域(singleton,prototype,web环境作用域),使用外部属性文件
- Spring 学习笔记(五)—— Bean之间的关系、作用域、自动装配
- Spring4 学习笔记(5)-Spring 的自动装配
- 使用Spring(九)自动装配(autowire)协作者
- Spring攻略笔记-3 自动装配
- spring学习笔记(13)——注解Autowired自动装配
- 【Spring学习笔记四】-自动装配Bean
- spring自动装配与spring_bean之间的关系(二)
- ITCAST视频-Spring学习笔记(@Autowire注解与自动装配)
- Spring4学习笔记(五):Bean的自动装配
- Spring 学习笔记 -beans 的自动扫描与装配和管理
- Spring 学习笔记【一】自动装配bean
- Spring学习笔记——Spring的自动装配
- Spring内核研究-管理bean之间的关系三(自动装配)
- [Spring]Bean的自动装配Autowire【学习笔记】
- spring学习笔记三 自动装配
- J2EE系列之Spring4学习笔记(六)--IOC详解(bean之间的关系,bean的作用范围)
- Spring 学习笔记(2)——自动装配
- spring笔记——bean自动装配的5种模式(autowrite属性)
- 用spring的注解建立bean与bean之间的关系组件装配及自动注入依赖对象