Autowiring By Name
Explore the autowiring by name technique in Spring to inject dependencies by matching the reference variable name with the bean name. Understand how this differs from autowiring by type and the priority rules involving the @Primary annotation. Learn to apply autowiring by name to control bean selection in different scenarios effectively.
We'll cover the following...
Autowiring by name in Spring
In the last lesson, we looked at the autowiring by type approach where priority was given to the collaborative filter using the @Primary annotation.
Another approach is autowiring by name where we specify the bean that is to be used by name. In this approach, while creating an object, the dependency is injected by matching the name of the reference variable to the bean name. The developer has to ensure that the variable name is the same as its bean name.
Implementation
For the code example shown in this lesson, we have created a ...