title: Partial auto-wire Spring prototype bean with runtime determined constructor arguments
body: <p>The javadoc to <code>ConstructorResolver.autowireConstructor(...)</code> says</p>
  
  <blockquote>
    <p>Also applied if explicit constructor argument values are specified, matching all remaining arguments with beans from the bean factory.</p>
  </blockquote>
  
  <p>but I can't get it to work. I get a <code>BeanCreationException</code>:</p>
  
  <blockquote>
    <p>Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)</p>
  </blockquote>
  
  <p>In this example, I have a bean with a constructor that takes Spring beans as well as a <code>String</code> and an <code>int</code> that will only be known at runtime.</p>
  
  <pre><code>@Component
  @Scope(BeanDefinition.SCOPE_PROTOTYPE)
  public class BeanWithRuntimeDependencies {
  
      public final DependencyA dependencyA;
      public final DependencyB dependencyB;
      public final String myString;
      public final int myInt;
  
      public BeanWithRuntimeDependencies(
              DependencyA dependencyA, DependencyB dependencyB, 
              String myString, int myInt) {
          this.dependencyA = dependencyA;
          this.dependencyB = dependencyB;
          this.myString = myString;
          this.myInt = myInt;
      }
  
  }
  
  @Component
  public class DependencyA { /* ... */ }
  
  @Component
  public class DependencyB { /* ... */ }
  </code></pre>
  
  <p>and my test:</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest
  public class PrototypeBeanConstructorsApplicationTests {
  
      @Autowired private ApplicationContext context;
  
      @Autowired private DependencyA dependencyA;
  
      @Autowired private DependencyB dependencyB;
  
      @Test
      public void getBeanFromContext() {
          BeanWithRuntimeDependencies bean = 
              context.getBean(BeanWithRuntimeDependencies.class, "runtime string", 10);
          assertNotNull(bean);
          assertEquals(dependencyA, bean.dependencyA);
          assertEquals(dependencyB, bean.dependencyB);
          assertEquals("runtime string", bean.myString);
          assertEquals(10, bean.myInt);
      }
  
  }
  </code></pre>
  
  <p>The source code of <code>ConstructorResolver.autowireConstructor(...)</code> has a comment:</p>
  
  <pre><code>// Explicit arguments given -&gt; arguments length must match exactly.
  </code></pre>
  
  <p>which seems to contradict its javadoc.</p>
  
  <p>Is it possible to do this? What I am I doing wrong?</p>