In spring framework, setting bean dependencies in configuration files is a good practice to follow, but the spring container is also able to autowire relationships between collaborating beans. This means that it is possible to automatically let Spring resolve collaborators (other beans) for your bean by inspecting the contents of the BeanFactory. Autowiring is specified per bean and can thus be enabled for some beans, while other beans will not be autowired.
In Spring, 5 Auto-wiring modes are supported.
no – Default, no auto wiring, set it manually via “ref” attribute
byName – Auto wiring by property name. If the name of a bean is same as the name of other bean property, auto wire it.
byType – Auto wiring by property data type. If data type of a bean is compatible with the data type of other bean property, auto wire it.
constructor – byType mode in constructor argument.
autodetect – If a default constructor is found, use “autowired by constructor”; Otherwise, use “autowire by type”.
Advantage of Autowiring
It requires less code because we don't need to write the code to inject the dependency explicitly.
Disadvantage of Autowiring
No control of programmer.
It can't be used for primitive and string values.