Auto-wiring in Spring
So far, we have learned how to define configuration metadata along with<bean>
to set the dependencies. How good would it be if everything was settled down without giving any instruction in the form of configuration? That is a cool idea, and the good news is that Spring supports it.
This feature is called autowire (in Spring terminology), which automates the process of binding relations between beans. This greatly reduces the effort of providing configuration metadata at either properties or constructor arguments.
The autowire feature can be enabled in XML-based configuration metadata by defining the autowire
attribute of the <bean>
element. It can be specified with the following three modes: name, type, and constructor. By default, autowire is set off for all beans.
Auto-wiring by name
As its name suggests, in this mode, Spring does the wiring of beans by name. Spring looks for beans with the same name (ID) as the property that needs to be autowired. In other...