title: What is the logic in spring to choose constructor when ambiguity constructors prasents
body: <p>First i need to tell <strong>I know how to solve this problem using type and index in Spring config file. but i want to learn how spring chose constructor when ambiguity constructors are presents</strong>.</p>
  
  <p>Pojo Class</p>
  
  <pre><code>package a.b.c;
  
  public class Square {
  
      private String color;
      private int sideLength;
  
      public Square(String color, int sideLength) {
          System.out.println("Constructor id #1");
          this.sideLength = sideLength;
          this.color = color;
      }
  
      public Square(int sideLength, String color) {
          System.out.println("Constructor id #2");
          this.sideLength = sideLength;
          this.color = color;
      }
  
      public Square(Integer sideLength, String color) {
          System.out.println("Constructor id #3");
          this.sideLength = sideLength;
          this.color = color;
      }
  
      public void draw() {
          System.out.println("square color : " + color + ", sideLenth : " + sideLength);
      }
  
  }
  </code></pre>
  
  <p>ApplicationContext.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"&gt;
  
      &lt;bean id="square" class="a.b.c.Square"&gt;
          &lt;constructor-arg type="java.lang.String" value="red" /&gt;
          &lt;constructor-arg type="int" value="10" /&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>calling class</p>
  
  <pre><code>package a.b.c;
  
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.support.ClassPathXmlApplicationContext;
  
  public class Application {
  
      public static void main(String[] args) {
  
          ApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext.xml");
  
          Square square = (Square) context.getBean("square");
          square.draw();
  
      }
  
  }
  </code></pre>
  
  <p>with this arrangement it <strong>pick number #2 Constructor</strong>.</p>
  
  <p>without any config change if swap constructor position in source file as below</p>
  
  <pre><code>package a.b.c;
  
  public class Square {
  
      private String color;
      private int sideLength;
  
      public Square(int sideLength, String color) {
          System.out.println("Constructor id #2");
          this.sideLength = sideLength;
          this.color = color;
      }
  
      public Square(String color, int sideLength) {
          System.out.println("Constructor id #1");
          this.sideLength = sideLength;
          this.color = color;
      }
  
      public Square(Integer sideLength, String color) {
          System.out.println("Constructor id #3");
          this.sideLength = sideLength;
          this.color = color;
      }
  
      public void draw() {
          System.out.println("square color : " + color + ", sideLenth : " + sideLength);
      }
  
  }
  </code></pre>
  
  <p>Nothing changed except method positions. <strong>now it pick #1 constructor</strong>.</p>
  
  <p>My question is what is the logic to pick constructor when ambiguity comes.</p>
  
  <p>Note: I know this can resolve using index. </p>