1. Autowire can allow you to inject dependency implicitly. (It internally uses setter or constructor injection)
2. Advantages: Reduce the amount of code.
3. Cons: cannot be controlled by the programmer. cannot be used on basic data types and string values.
4. Autowiring Modes Mode
| 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 the such case, the property name and bean name must is 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 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 has large number of parameters. |
| 5) |
AutoDetect |
It is deprecated since Spring 3. |
ByName and Bytype in another piece of essay.
[Spring] Autowire