- Autowiring is a
mechanismin Spring that allows the framework toautomatically detectand inject the dependent beans to the properties of the target bean without the need forexplicitconfiguration. - In simple words, when we apply autowiring, then Spring looks for the
dependentbeans in the container andautomatically injectsthem into the target object. - Benefits:
- This can
savea lot oftime and effort, especially in large-scale applications where there are a large number ofdependenciesbetween objects.
- This can
- Drawbacks:
- No
controlof the programmer. - It can't be used for
primitiveand not recommended forstringvalues.
- No
`
<bean class="com.autowire.demo.beans.com.autowire.demo.Account" id="account">
<property name="accountId" value="SV-101"/>
<property name="bal" value="50000.0"/>
</bean>
<bean class="com.autowire.demo.beans.com.autowire.demo.Customer" id="customer" autowire="byName">
<property name="name" value="Neeraj"/>
</bean>
`
- You will get the correct output since we’re autowiring
byNameand spring will try to get the name of dependent bean by theid.