Resolving NoUniqueBeanDefinitionException in Spring

preview_player
Показать описание
Resolving the 'NoUniqueBeanDefinitionException' in Spring.

The default dependency injection behavior of Spring is to Autowire by type, and if more than one bean of a specific type is in the Spring Context, Spring may throw a NoUniqueBeanDefinitionException. In this video, I show you two different ways to resolve the NoUniqueBeanDefinitionException exception in Spring.

Рекомендации по теме
Комментарии
Автор

Thank you. I had my very first Spring class today. I wanted to do something that had me in the situation of having multiple implementations to an interface and that part wasn't covered (yet?).
So I did my very own demo of this for my own comprehension of Spring.
I also used a version using the Resource annotation. We were taught that one today but passing the class identifier as String in its name property kinda like Qualifier. The good thing is there is another type property I can use instead to avoid magic strings. It is precisely what I don't like about Qualifier. I shall find a way to extract and format the class name in a way that is not too verbose but I could not succeed for it also expects that string to be a constant.
Also I noticed that Resource is fine on its own. Autowired is mandatory with Qualifier.

This video was very helpful.

uchitesting
Автор

What if the 2 Bean names are the same (can happen if they're in different packages)?

atech