Spring DI- Constructor Injection with XML Metadata configuration

Constructor of Address class:

     public Address(String flatNo, String bldgNo, String streetNo, String city,int pincode) {
       this.flatNo = flatNo;
       this.bldgNo = bldgNo;
       this.streetNo = streetNo;
       this.city = city;
       this.pincode = pincode;

    <bean id="companyWithConstInjectionArg">
      <constructor-arg  value="276002"></constructor-arg>
      <constructor-arg  value="360"></constructor-arg>
      <constructor-arg  value="My City"></constructor-arg>
      <constructor-arg  value="My Street"></constructor-arg>
      <constructor-arg  value="C2"></constructor-arg>

Here spring container could not resolve matching constructor. Container can not identify which one should be treated as int and which one should be treated as String.
To avoid this kind of ambiguity index/type/name matching could be used.

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.