[Spring] Autowire
Posted zZ
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Spring] Autowire相关的知识,希望对你有一定的参考价值。
1. Autowire可以让你隐式地注入依赖.(it internally uses setter or constructor injection)
2.优点:减少代码量.
3.缺点:无法被程序员控制. 不能用在基本数据类型和string值.
4. Autowiring Modes模式
1) | no | It is the default autowiring mode. It means no autowiring bydefault. |
2) | byName | The byName mode injects the object dependency according to name of the bean. In such case, property name and bean name must be same. It internally calls setter method. |
3) | byType | The byType mode injects the object dependency according to type. So property name and bean name can be different. It internally calls setter method. |
4) | constructor | The constructor mode injects the dependency by calling the constructor of the class. It calls the constructor having large number of parameters. |
5) | autodetect | It is deprecated since Spring 3. |
byName和byType在另一片随笔中.
以上是关于[Spring] Autowire的主要内容,如果未能解决你的问题,请参考以下文章
Spring全家桶笔记:Spring+Spring Boot+Spring Cloud+Spring MVC
学习笔记——Spring简介;Spring搭建步骤;Spring的特性;Spring中getBean三种方式;Spring中的标签
Spring框架--Spring事务管理和Spring事务传播行为