NoUniqueBeanDefinitionException: No qualifying bean of type in spring, need of @Qualifier

The story will tell about the scenario of the application failed to start due to an exception org. spring framework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type.

I will explain the one scenario that happens. As described in the image we have class One that implements interface A and class Two extend class B and interface B.

I have one action, facade, or handler component class where I need to invoke for service for two different purposes.

As per HandlerClass uses the @Autowired
private InterfaceA interfaceA;

@Autowired
private Interfaceb interfaceB.

Here we will get the compile-time error like Could not autowire there is more than bean.

Reason

You have two classes marked as being Spring autowired components.

You can only have one active in the runtime code.

This normally happens to me when I have an interface and then have two implementations that I want to switch via config.

Autowire Conflict Resolution

There are two simple ways you can resolve the NoUniqueBeanDefinitionException exception in Spring. You can use the

Solution

@Primary

The second way is to use the

@Qualifier

Java 8 | Spring | React | Angular | CI/CD | Microservices | Monitoring |Apache Kafka. https://www.linkedin.com/in/shuaib-kunhabdulla-83780188