Spring Framework @Qualifier example

By | June 22, 2021

In this post, We will learn about the Spring Framework @Qualifier example using a Demo Project.

The @Qualifier annotation is used to resolve the auto wiring conflict when there are multiple beans of the same type.

The @Qualifierannotation can be used within the class before any class property. This annotation may also be applied to constructor arguments or method parameters.

pom.xml

Employee.java

In this class, you can see we have used @Qualifier (“address2”)(along with  @Autowired annotation) annotation before the address property. As we have two Spring beans of com.kkhindigyan.model.Address Type in applicationContext.xml. so to resolve this ambiguity

Here We have used @Qualifier (“address2”) annotation so It will autowire “address2” bean with address property in Employee class, If we do not use @Qualifier annotation here then Spring will throw below Exception

Address.java

applicationContext.xml

ClientTest.java

Client Class with the main method.

If you run ClientTest.java as Java Application then it will give the below output:

That’s all about the Spring Framework @Qualifier example

You May Also Like:

Spring BeanFactory Container Example
Spring ApplicationContext Container Example
Annotation-based Configuration in Spring Framework Example
Spring Java-based Configuration Example
Spring Setter Dependency Injection Example
Spring @Autowired Annotation With Setter Injection Example
Spring Constructor based Dependency Injection Example
Spring @Autowired Annotation With Constructor Injection Example
Spring Autowiring byName & byType Example
getBean() overloaded methods in Spring Framework
Spring Inner bean example
Spring Dependency Injection with Factory Method
Injecting Collections in Spring Framework Example
Spring Bean Definition Inheritance Example
Spring bean scopes with example
Spring JSR-250 Annotations with Example
Spring BeanPostProcessor Example
Spring JDBC Integration Example
Spring JDBC Annotation Example
Spring with Jdbc java based configuration example
Spring JDBC NamedParameterJdbcTemplate Example
How to call stored procedures in the Spring Framework?

If you have any feedback or suggestion please feel free to drop in below comment box.

Leave a Reply

Your email address will not be published.