Autowiring in Spring Example – Autowire byType

Autowiring in Spring Example – Autowire byType

Autowire byName
If the name or id of the bean declared in applicationContext.xml (or xml which you create) is same as the name of the bean property then autowire byName can be applied

Autowire byType
Means it will search for one bean of given property in the container(Only one bean). If there are more than one bean, then it will not autowire.

Autowire Constructor
It will search for compatible constructor with given parameters

Autowire byName

Directory Structure


Note: autowire byType applies for exactly one type, here we have declared only one type of bean and it has applied to that. In output you can see, the value for employee2.getEname() also shows the same value of employee1.getEname(). This is cause the byType applies depending on the type








Leave a Reply

Your email address will not be published. Required fields are marked *