码迷,mamicode.com
首页 > 编程语言 > 详细

[Spring] Autowire

时间:2018-06-02 18:39:34      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:ted   基本数据   nal   tab   cat   依赖   无法   lin   des   

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

标签:ted   基本数据   nal   tab   cat   依赖   无法   lin   des   

原文地址:https://www.cnblogs.com/zienzir/p/9126078.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!