I encounter same issue as this. I know how to solve this, but I don't know why this is happening.
As this mentioned, by default the spring injection is by type
, not by name
. That's why we can inject the implementation to the interface.
In my spring web application, I am injecting the corresponding interface, while resolving by type, it should find the exact concrete class, but I encounter exception ConflictingBeanDefinitionException
:
interface A;
interface B;
Class com.level1.Child implements A;
Class com.level2.Child implements B;
@Autowired
private B b; // expecting com.level2.Child obviously!
How come? Any better way to solve this? This is very annoying, because I need to annotate Qualifier
at a lot of variables, due to there are many same class name in different packages of my application.