title: Some doubts about how exactly work the XML constructor injection Spring configuration?
body: <p>I am studying Sping <strong>XML configuration</strong> and I have the following doubt related to the <strong>constructor injection configuration</strong>.</p>
  
  <p>So I have the following example:</p>
  
  <pre><code>&lt;bean id=“transferService” class=“com.acme.TransferServiceImpl”&gt;
      &lt;constructor-arg ref=“accountRepository”/&gt;
      &lt;constructor-arg ref=“customerRepository”/&gt;
  &lt;/bean&gt;
  
  &lt;bean id=“accountRepository” class=“com.acme.AccountRepositoryImpl”/&gt;
  &lt;bean id=“customerRepository” class=“com.acme.CustomerRepositoryImpl”/&gt;
  </code></pre>
  
  <p>Ok. It is pretty clear for me what happens: first the <strong>accountRepository</strong> bean is created as an <strong>com.acme.AccountRepositoryImpl</strong> instance and the <strong>customerRepository</strong> bean is created as an <strong>com.acme.CustomerRepositoryImpl</strong> instance</p>
  
  <p>Then is created the <strong>transferService</strong> bean as an istance of the <strong>com.acme.TransferServiceImpl</strong> class and the previous 2 bean are injected as input paramether of the constructor during the bean construction.</p>
  
  <p>This is clear. My doubt is related to the fact that on the documentation I read that:</p>
  
  <blockquote>
    <p><strong>Parameters injected according to their type</strong></p>
  </blockquote>
  
  <p>What it exactly means? It seems to me that in the previous configuration the beans are injected according to their id.</p>
  
  <p>The previous statement means that Spring check the type and for example if the constructor of the <strong>TransferServiceImpl</strong> class take 2 paramethers having type <strong>AccountRepositoryImpl</strong> and <strong>CustomerRepositoryImpl</strong> it perform the matching?</p>
  
  <p>So it means that:</p>
  
  <pre><code>&lt;bean id=“transferService” class=“com.acme.TransferServiceImpl”&gt;
      &lt;constructor-arg ref=“accountRepository”/&gt;
      &lt;constructor-arg ref=“customerRepository”/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>is the same thing of:</p>
  
  <pre><code>&lt;bean id=“transferService” class=“com.acme.TransferServiceImpl”&gt;
      &lt;constructor-arg ref=“customerRepository”/&gt;
      &lt;constructor-arg ref=“accountRepository”/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>?</p>
  
  <p>Changing the order of the paramethers the result don't change because Spring perform the matching for me? If yes what happens if in the constructor I have more paramether that have the same type?</p>
  
  <p>Tnx</p>