1

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.

Sam YC
  • 10,725
  • 19
  • 102
  • 158
  • Could you please provide more details about how the beans are instantiated in the app: with .xml | `@Component`s through package scan | as `@Bean`s ? – Antot Mar 13 '18 at 08:39

1 Answers1

0

If multiple beans are defined with the same name, then the one defined later will override the one defined earlier.

I advice you to rename your Childs into ChildA and ChildB.

Pasha
  • 1,768
  • 6
  • 22
  • 43