Spring bean injection from xml error : expected single matching bean but found

StackOverflow https://stackoverflow.com/questions/21761046

  •  11-10-2022
  •  | 
  •  

سؤال

We are using Spring to create service beans for our tests.

I get error : Could not autowire field: private x.y.A expected single matching bean but found 2 [A,AA]

Code:

public class ATest {

    @Autowired
    private A a;

xml

<bean id="ida" class="x.y.A" />

<bean id="idaa" class="x.y.AA" />

Where:

AA.java  

class AA extends A { ... }

Cs

هل كانت مفيدة؟

المحلول

use

@Autowired
@Qualifier("idaa")
private A a;

check the documentation

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top