title: Instantiate base class when child does not implement all constructors
body: <p>Consider a simple bean:</p>
  
  <pre><code>@Component
  @Scope(BeanDefinition.SCOPE_PROTOTYPE)
  public class A {
      public A(Integer a){}
      public A(String a){}
  }
  </code></pre>
  
  <p>Having an instance of <a href="https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/beans/factory/BeanFactory.html" rel="nofollow noreferrer"><code>BeanFactory</code></a> I can create <code>A</code> instances with:</p>
  
  <pre><code>beanFactory.getBean(A.class, 1); //  using A(Integer)
  beanFactory.getBean(A.class, "1"); //  using A(String)
  </code></pre>
  
  <p>Now, I want to have a subclass of <code>A</code> that uses one of the two constructors provided. My class hierarchy now becomes:</p>
  
  <pre><code>@Component
  @Scope(BeanDefinition.SCOPE_PROTOTYPE)
  @Primary
  public class A {
      public A(Integer a) {}
      public A(String a) {}
  }
  
  @Component
  @Scope(BeanDefinition.SCOPE_PROTOTYPE)
  public class A1 extends A {
      public A1() { super(1); }
  }
  </code></pre>
  
  <p>I would expect these to work now:</p>
  
  <pre><code>beanFactory.getBean(A.class, 1); // using A(Integer)
  beanFactory.getBean(A.class, "1"); // using A(String)
  beanFactory.getBean(A1.class); // using the A1()
  </code></pre>
  
  <p>However, first two calls fail with </p>
  
  <pre><code>org.springframework.beans.factory.BeanCreationException: 
  Error creating bean with name 'A1' defined in file [...]: Could not resolve matching constructor 
  (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
  </code></pre>
  
  <p>Please note that I'm not trying to create subclass with some argument like author of <a href="https://stackoverflow.com/questions/21583399/could-not-resolve-matching-constructor-error-when-passing-in-constructor-arg-f">this question</a>.</p>
  
  <p>Also note that if I define (useless) <code>A1(Integer)</code> and <code>A1(String)</code> constructors, Spring does not complain anymore.</p>
  
  <p>Using Spring 4.2.2.RELEASE.</p>
  
  <p><strong>Why bean factory can not create base class instances with its constructors when I define some child?</strong></p>
  
  <p>Please find an unit test reproducing it <a href="https://github.com/fracz/stackoverflow-problems/blob/spring-ioc-instantiation-problem/src/test/java/com/example/ioctest/IocIntegrationTest.java" rel="nofollow noreferrer">in Github repo</a>.</p>