[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在另一片随笔中.

猜你喜欢

转载自www.cnblogs.com/zienzir/p/9126078.html
今日推荐