What is auto wiring?
The Spring container provides the functionality of connecting beans with each other automatically called autowiring . Rather we inject one bean into the other using ref attribute, Spring can look into the BeanFactory and decide how to inject one bean into the other. So we don’t explicitly connect (wire) beans instead spring does this for us.
Autowiring helps to minimize the need to specify properties or constructor arguments, thus saves a lot of typing . Autowiring is specific to individual beans, a bean may or may not use autowiring.
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”.
Autowiring helps to minimize the need to specify properties or constructor arguments, thus saves a lot of typing . Autowiring is specific to individual beans, a bean may or may not use autowiring.
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”.
Comments
Post a Comment