- 浏览: 141104 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
java_web_hack1:
HashMap和HashTable区别 几乎是百分之百会出现老 ...
面试 java -
hj01kkk:
剖析地很深入,谢谢!!
Java:单例模式的七种写法 -
hj01kkk:
很不错
Java:单例模式的七种写法 -
sunway00:
Map<Integer, String> ha ...
为KeySet遍历HashMap辟谣---效率问题 -
Shen.Yiyang:
ddlgyq 写道lyplyz 写道如果你在循环中只用key, ...
为KeySet遍历HashMap辟谣---效率问题
Spring的autowire自动装配bean的四种方式
- 博客分类:
- 转载
default
[html] view plaincopyprint?<?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.xsd">
<bean id="computerBean" class="www.csdn.spring.bean.ComputerBean">
<property name="name" value="Dell n5110" />
</bean>
<bean id="deptBean" class="www.csdn.spring.bean.DeptBean">
<property name="name" value="CSDN教育事业部" />
</bean>
<bean id="employeeBean" class="www.csdn.spring.bean.EmployeeBean">
<property name="name" value="hahahha"/>
<property name="computerBean" ref="computerBean"/>
<property name="deptBean" ref="deptBean" />
</bean>
</beans>
<?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.xsd">
<bean id="computerBean" class="www.csdn.spring.bean.ComputerBean">
<property name="name" value="Dell n5110" />
</bean>
<bean id="deptBean" class="www.csdn.spring.bean.DeptBean">
<property name="name" value="CSDN教育事业部" />
</bean>
<bean id="employeeBean" class="www.csdn.spring.bean.EmployeeBean">
<property name="name" value="hahahha"/>
<property name="computerBean" ref="computerBean"/>
<property name="deptBean" ref="deptBean" />
</bean>
</beans>
byName
[html] view plaincopyprint?<?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.xsd">
<bean id="computerBean" class="www.csdn.spring.bean.ComputerBean">
<property name="name" value="Dell n5110" />
</bean>
<bean id="deptBean" class="www.csdn.spring.bean.DeptBean">
<property name="name" value="CSDN教育事业部" />
</bean>
<bean id="employeeBean" class="www.csdn.spring.bean.EmployeeBean"
autowire="byName">
<property name="name" value="hahahha"/>
</bean>
</beans>
<?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.xsd">
<bean id="computerBean" class="www.csdn.spring.bean.ComputerBean">
<property name="name" value="Dell n5110" />
</bean>
<bean id="deptBean" class="www.csdn.spring.bean.DeptBean">
<property name="name" value="CSDN教育事业部" />
</bean>
<bean id="employeeBean" class="www.csdn.spring.bean.EmployeeBean"
autowire="byName">
<property name="name" value="hahahha"/>
</bean>
</beans>
byType
[html] view plaincopyprint?<?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.xsd">
<bean id="computerBean" class="www.csdn.spring.bean.ComputerBean">
<property name="name" value="Dell n5110" />
</bean>
<bean id="deptBean" class="www.csdn.spring.bean.DeptBean">
<property name="name" value="CSDN教育事业部" />
</bean>
<bean id="employeeBean" class="www.csdn.spring.bean.EmployeeBean"
autowire="byType">
<!-- <property name="name" value="hahahha"/> -->
<!-- <property name="computerBean" ref="computerBean"/>
<property name="deptBean" ref="deptBean" /> -->
</bean>
</beans>
<?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.xsd">
<bean id="computerBean" class="www.csdn.spring.bean.ComputerBean">
<property name="name" value="Dell n5110" />
</bean>
<bean id="deptBean" class="www.csdn.spring.bean.DeptBean">
<property name="name" value="CSDN教育事业部" />
</bean>
<bean id="employeeBean" class="www.csdn.spring.bean.EmployeeBean"
autowire="byType">
<!-- <property name="name" value="hahahha"/> -->
<!-- <property name="computerBean" ref="computerBean"/>
<property name="deptBean" ref="deptBean" /> -->
</bean>
</beans>
constructor
[html] view plaincopyprint?<?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.xsd">
<bean id="computerBean" class="www.csdn.spring.bean.ComputerBean">
<property name="name" value="Dell n5110" />
</bean>
<bean id="deptBean" class="www.csdn.spring.bean.DeptBean">
<property name="name" value="CSDN教育事业部" />
</bean>
<!-- <bean id="employeeBean" class="www.csdn.spring.bean.EmployeeBean"
autowire="constructor">
</bean> -->
<bean id="employeeBean" class="www.csdn.spring.bean.EmployeeBean"/>
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"></bean>
</beans>
[html] view plaincopyprint?<?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.xsd">
<bean id="computerBean" class="www.csdn.spring.bean.ComputerBean">
<property name="name" value="Dell n5110" />
</bean>
<bean id="deptBean" class="www.csdn.spring.bean.DeptBean">
<property name="name" value="CSDN教育事业部" />
</bean>
<bean id="employeeBean" class="www.csdn.spring.bean.EmployeeBean">
<property name="name" value="hahahha"/>
<property name="computerBean" ref="computerBean"/>
<property name="deptBean" ref="deptBean" />
</bean>
</beans>
<?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.xsd">
<bean id="computerBean" class="www.csdn.spring.bean.ComputerBean">
<property name="name" value="Dell n5110" />
</bean>
<bean id="deptBean" class="www.csdn.spring.bean.DeptBean">
<property name="name" value="CSDN教育事业部" />
</bean>
<bean id="employeeBean" class="www.csdn.spring.bean.EmployeeBean">
<property name="name" value="hahahha"/>
<property name="computerBean" ref="computerBean"/>
<property name="deptBean" ref="deptBean" />
</bean>
</beans>
byName
[html] view plaincopyprint?<?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.xsd">
<bean id="computerBean" class="www.csdn.spring.bean.ComputerBean">
<property name="name" value="Dell n5110" />
</bean>
<bean id="deptBean" class="www.csdn.spring.bean.DeptBean">
<property name="name" value="CSDN教育事业部" />
</bean>
<bean id="employeeBean" class="www.csdn.spring.bean.EmployeeBean"
autowire="byName">
<property name="name" value="hahahha"/>
</bean>
</beans>
<?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.xsd">
<bean id="computerBean" class="www.csdn.spring.bean.ComputerBean">
<property name="name" value="Dell n5110" />
</bean>
<bean id="deptBean" class="www.csdn.spring.bean.DeptBean">
<property name="name" value="CSDN教育事业部" />
</bean>
<bean id="employeeBean" class="www.csdn.spring.bean.EmployeeBean"
autowire="byName">
<property name="name" value="hahahha"/>
</bean>
</beans>
byType
[html] view plaincopyprint?<?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.xsd">
<bean id="computerBean" class="www.csdn.spring.bean.ComputerBean">
<property name="name" value="Dell n5110" />
</bean>
<bean id="deptBean" class="www.csdn.spring.bean.DeptBean">
<property name="name" value="CSDN教育事业部" />
</bean>
<bean id="employeeBean" class="www.csdn.spring.bean.EmployeeBean"
autowire="byType">
<!-- <property name="name" value="hahahha"/> -->
<!-- <property name="computerBean" ref="computerBean"/>
<property name="deptBean" ref="deptBean" /> -->
</bean>
</beans>
<?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.xsd">
<bean id="computerBean" class="www.csdn.spring.bean.ComputerBean">
<property name="name" value="Dell n5110" />
</bean>
<bean id="deptBean" class="www.csdn.spring.bean.DeptBean">
<property name="name" value="CSDN教育事业部" />
</bean>
<bean id="employeeBean" class="www.csdn.spring.bean.EmployeeBean"
autowire="byType">
<!-- <property name="name" value="hahahha"/> -->
<!-- <property name="computerBean" ref="computerBean"/>
<property name="deptBean" ref="deptBean" /> -->
</bean>
</beans>
constructor
[html] view plaincopyprint?<?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.xsd">
<bean id="computerBean" class="www.csdn.spring.bean.ComputerBean">
<property name="name" value="Dell n5110" />
</bean>
<bean id="deptBean" class="www.csdn.spring.bean.DeptBean">
<property name="name" value="CSDN教育事业部" />
</bean>
<!-- <bean id="employeeBean" class="www.csdn.spring.bean.EmployeeBean"
autowire="constructor">
</bean> -->
<bean id="employeeBean" class="www.csdn.spring.bean.EmployeeBean"/>
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"></bean>
</beans>
发表评论
-
CopyOnWriteArrayList
2014-10-17 13:58 494CopyOnWriteArrayList是ArrayLi ... -
Java多线程-工具篇-BlockingQueue
2013-09-03 23:22 1837一:前言: 在新增的Concurrent包中,Blo ... -
Java:单例模式的七种写法
2013-07-04 16:22 1643第一种(懒汉,线程不安全): 1 public cla ... -
Spring 资源访问剖析和策略模式应用
2013-06-21 18:07 874Spring 把所有能记录信息 ... -
Mysql Explain 详解
2013-06-08 13:28 754一.语法 explain < table_name & ... -
spring mvc 框架搭建及详解
2013-05-08 09:04 844现在主流的Web MVC框架除了Struts这个主力 外,其次 ... -
Spring 使用注解方式进行事务管理
2013-05-08 09:05 1098大家在使用spring的注解 ... -
Spring MVC framework深入分析
2013-05-08 09:06 823在当今的MVC framework里, ... -
JMS 异步传输与Spring结合实例
2013-05-08 09:06 1234在Spring 2.0之前,Spring的JMS的作用局限于产 ... -
spring scope自定义
2013-05-07 22:39 1128BeanFactory除了拥有作为IoC Service Pr ... -
Spring总结
2013-05-07 22:34 703一、Spring中JDK的动态代 ... -
二叉查找树
2013-05-07 22:31 730二叉查找树 二叉查找树(B ... -
mysql字符串长度的一些问题
2013-05-07 22:14 1196length: 是计算字段的长度一个汉字是算三个字符,一个 ... -
HIGH_PRIORITY/LOW_PRIORITY/INSERT DELAYED
2013-05-03 18:18 1069MySQL 还允许改变语句调 ... -
BIT_COUNT()&BIT_OR()
2013-05-02 21:04 709在学习MySQL手册时,看 ... -
mysql时间函数
2013-04-30 20:38 771一、MySQL 获得当前日期时间 函数 1.1 获得当前日期+ ... -
SQL中EXISTS的用法
2013-04-28 11:51 687SELECT c.CustomerId,CompanyName ... -
sql之left join、right join、inner join的区别
2013-04-28 10:09 756sql之left join、right join、inner ... -
关于with cube ,with rollup 和 grouping
2013-04-28 09:37 783http://www.cnblogs.com/shuangne ... -
Spring的注解
2013-03-29 11:25 746注释配置相对于 XML 配置具有很多的优势: 它可以充分利用 ...
相关推荐
04_Spring的三种实例化Bean的方式 05_配置Spring管理的bean的作用域 06_Spring管理的Bean的生命周期 07_编码剖析Spring依赖注入的原理 08_编码剖析Spring装配基本属性的原理 09_Spring如何装配各种集合类型的...
使用autowire属性指定自动装配的方式byName根据bean的名字和当前bean的setter风格属性名进行自动装配若有匹配,则自动转配若无匹配,则不装配
#学习springboot自动装配 ##一,手动装配 ### 1,模式注解装配 @Component注解,或者@Component注解的扩展,@ Controller,@ Service,存储库,@ Configruation等, ### 2. @ Configuration启动容器+ @ Bean注册...
八、 自动装配autowire 13 (一) byName 13 (二) byType 14 (三) 注意 14 九、 生命周期 15 (一) lazy-init/default-lazy-init 15 (二) init-method destroy-method 不要和prototype一起用(了解) 15 第六课:...
装配Bean “initialization on demand holder”创建单例模式的理解,参考 Spring中单例的概念限于Spring上下文中,遵守约定 内部bean适用于setter注入和构造器注入,内部bean不能被复用 SpEL表达式 3. 高级装配 4 种...
spring基础,主要讲解了 spring的autowire:自动装配 collections:属性配置的细节 properties:外部属性文件的使用 relati:bean之间的关系 scope:bean的作用域 spel:spel的使用
3.3.6. 自动装配(autowire)协作者 3.3.6.1. 设置Bean使自动装配失效 3.3.7. 依赖检查 3.3.8. 方法注入 3.3.8.1. Lookup方法注入 3.3.8.2. 自定义方法的替代方案 3.4. bean的作用域 3.4.1. Singleton作用域 3.4.2. ...
3.3.5. 自动装配(autowire)协作者 3.3.6. 依赖检查 3.3.7. 方法注入 3.4. Bean的作用域 3.4.1. Singleton作用域 3.4.2. Prototype作用域 3.4.3. Singleton beans和prototype-bean的依赖 3.4.4. 其他作用域 ...
3.3.6. 自动装配(autowire)协作者 3.3.7. 依赖检查 3.3.8. 方法注入 3.4. bean的作用域 3.4.1. Singleton作用域 3.4.2. Prototype作用域 3.4.3. 其他作用域 3.4.4. 自定义作用域 3.5. 定制bean特性 3.5.1...
3.3.5. 自动装配(autowire)协作者 3.3.6. 依赖检查 3.3.7. 方法注入 3.4. Bean的作用域 3.4.1. Singleton作用域 3.4.2. Prototype作用域 3.4.3. Singleton beans和prototype-bean的依赖 3.4.4. 其他作用域 ...
八、 自动装配autowire 13 (一) byName 13 (二) byType 14 (三) 注意 14 九、 生命周期 15 (一) lazy-init/default-lazy-init 15 (二) init-method destroy-method 不要和prototype一起用(了解) 15 第六课:...
3.3.6. 自动装配(autowire)协作者 3.3.7. 依赖检查 3.3.8. 方法注入 3.4. bean的作用域 3.4.1. Singleton作用域 3.4.2. Prototype作用域 3.4.3. 其他作用域 3.4.4. 自定义作用域 3.5. 定制bean特性 3.5.1...
概述Mockitobeans是一个 ,通过使用Spring自己的@Autowire语法,您可以无缝地对所有bean进行自动装配。历史mockitobeans时,我一直在寻找一种方式来开始使用嘲笑说已经自动装配依赖其中有额外的自动装配Autowired的...
指定Spring框架的自动装配模式, 该属性的默认值是name, 即默认根据Bean的name属性自动装配. struts.objectFactory.spring.useClassCache 该属性指定整合Spring框架时,是否缓存Bean实例,该属性只允许使用true和false...