title: Autowiring Spring superclass
body: <p>Why does Spring automatically choose the superclass types during autowiring?</p>
  
  <p>For instance, if I have</p>
  
  <pre><code>@Component
  public class Foo {}
  
  @Component
  public class Bar extends Foo {}
  </code></pre>
  
  <p>and someone autowires</p>
  
  <pre><code>@Autowired
  private Foo foo;
  </code></pre>
  
  <p>How come Spring always chooses the supertype <code>Foo</code>? Shouldn't this be an "<strong>ambiguous</strong>" mapping (and cause Spring to throw an error)?</p>
  
  <p>Don't you technically have <strong>two</strong> <code>Foo</code> candidates? (e.g., Bar gets <em>automatically picked</em> when @Component is removed from Foo...)</p>