title: Spring Autowire Annotation on Abstract class: No unique bean is defined
body: <p>I've got an abstract class:</p>
  
  <pre><code>@Component
  public abstract class BaseReport {
  
    public void export() {
     ...
  }
  </code></pre>
  
  <p>And a bunch of classes that extend it, and override the export() method (or not). </p>
  
  <pre><code>@Component
  public final class Report1 extends BaseReport
  
  @Component
  public final class Report2 extends BaseReport
  </code></pre>
  
  <p>Most of my tests autowire concrete classes that extend BaseReport, with no problems:</p>
  
  <pre><code>public class Report1Test extends BaseTest {
  
      @Autowired
      Report1 _report;
  
  public class Report2Test extends BaseTest {
  
      @Autowired
      Report2 _report;
  </code></pre>
  
  <p>This works fine for autowiring of all classes that <em>extend</em> BaseReport. But I also need to autowire the abstract class itself, BaseReport, to test the export() method. </p>
  
  <pre><code>public class BaseReportTest extends BaseTest {
  
    @Autowired
    BaseReport _report;
  </code></pre>
  
  <p>When I try to run it I get the infamous:</p>
  
  <p><em>No unique bean of type BaseReport is defined: expected single matching bean but found 2 [Report1, Report2].</em></p>
  
  <p>I've tried using @Qualifier but the problem with @Qualifier is that (as I understand it) you use it to tell Spring which class -- that implements an Interface or extends an Abstract class - you wish to use. But that's not my case. I want to use the abstract class itself.</p>
  
  <p>I also tried using @Resource, like this:</p>
  
  <pre><code>public class BaseReportTest extends BaseTest {
  
    @Resource(name = "baseReport")
    BaseReport _report;
  </code></pre>
  
  <p>Spring tells me there is no bean with this name. :(</p>
  
  <p>How can I do this?</p>
  
  <p>Cheers.</p>