title: How can we pass the value to multiple parameterized constructor through xml file in spring?
body: <pre><code>        I have three files
          1) Test.java (in which i have created two parameterized constructor)
          2) spring.xml (xml file)
          3) Client.java(in which i have created main method)
  
          1)Test.java
  
          public class Test {
          private String name,email;
          private int age;
  
              public Test(String name,int age)
              {
                  this.name=name;
                  this.age=age;
              }
              public Test(String name)
              {
                  this.name=name;
              }
              public void display()
              {
                  System.out.println("First Constructor "+name+" "+age);
                  System.out.println("Second Constructor "+name);
  
              }
          }
  
  
  
      2) spring.xml
  
      &lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
      "http://www.springframework.org/dtd/spring-beans-2.0.dtd"&gt;
  
      &lt;beans&gt;
      &lt;bean id="testObj" class="Test" &gt;
  
      &lt;constructor-arg value="name"  index="0"/&gt;
  
      &lt;constructor-arg value="123"  index="1"/&gt;
  
      &lt;constructor-arg value="name"/&gt;
  
      &lt;/bean&gt;
      &lt;/beans&gt;
  
  3) Client.java
  
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.support.ClassPathXmlApplicationContext;
  </code></pre>
  
  <p>public class Client {</p>
  
  <pre><code>    public static void main(String[] args) {
  
          ApplicationContext context=new ClassPathXmlApplicationContext("resource/spring.xml");
          Test t1=(Test)context.getBean("testObj");
          t1.display();
      }
  
  }
  </code></pre>
  
  <p>when i am calling only single constructor its working fine but in case of calling both of them its giving exception:
  Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testObj' defined in class path resource [resource/spring.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)</p>