title: Creating 2 beans of the same class with different constructor-args and using autowiring
body: <p>Hi I working on a project, in which I need to create 2 instances of bean of same class but different constructor-args. Right now have functionality only for "production environment", so I have xml file like:</p>
  
  <pre><code>&lt;context:component-scan base-package="com.xxx.yyy" /&gt; 
      &lt;bean id="id1" class="someCompanySpecificURLForTheClass" scope="singleton"/&gt;
  
    &lt;bean name="name1" factory-bean="id1" factory-method="createFullClient"&gt;
      &lt;constructor-arg index="0"&gt;
          &lt;ref bean="someJSONBean"/&gt;
      &lt;/constructor-arg&gt;
      &lt;constructor-arg value="productionEnv" index="1"/&gt;
  &lt;/bean&gt;  
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>Now I need to include functionality for testing environment also. So I changed the xml file to:</p>
  
  <pre><code>&lt;context:component-scan base-package="com.xxx.yyy" /&gt;
  &lt;context:component-scan base-package="com.zzz.yyy" /&gt; 
  
   &lt;bean id="id1" class="someCompanySpecificURLForTheClass" scope="prototype"/&gt;
  
    &lt;bean name="name1" factory-bean="id1" factory-method="createFullClient"&gt;
      &lt;constructor-arg index="0"&gt;
          &lt;ref bean="someJSONBean"/&gt;
      &lt;/constructor-arg&gt;
      &lt;constructor-arg value="${value.name}" index="1"/&gt;
  &lt;/bean&gt; 
  </code></pre>
  
  <p>In the 2 Java files, I use <strong>@Autowired</strong> annotations on the method of <strong>setClients()</strong> and on creating object of <strong>someJSONBean</strong>. </p>
  
  <p>But I am receiving errors:</p>
  
  <pre><code>BeanCreationException: could not autowire method: public void com.zzz.yyy.sometthing.setClients(someCompanySpecificURLForTheClass) throws IllegalArgumentException and UnsupportedEncodingException.
  nested exception is defined: NoSuchBeanDefinitionException: no unique bean of type(someCompanySpecificURLForTheClass) is defined: expected single matching bean, found 2(name1, name2).
  </code></pre>
  
  <p>I am new to spring framework. can anyone tell whats happening wrong, is the autowiring that i am doing wrong? how can i solve this?</p>
  
  <p>Edit:
  Here <strong>someCompanySpecificURLForTheClass</strong> is the same class and beans(name1 and name2) use this bean as a factory bean with different constructor-arguments.<br/>
  I am using spring 3.1.<br/>
  After searching a lot, I think I can use placeholder for the constructor-args value right? 
  The above is the edited xml file being used.
  Updated code in the Java classes:
  1. </p>
  
  <pre><code>@ConfigAdapter
   class class1{
  
    @Autowired
    private someJSONBean obj;
  
    @Autowired
    @Value("${value.name:thisismyvalue}")
    public void setClients(){}
  }
  
   @ConfigAdapter
   class class2{
  
    @Autowired
    private someJSONBean obj;
  
    @Autowired
    @Value("${value.name:thisismyvalue}")
    public void setClients(){}
  }
  </code></pre>
  
  <p>But I get the following error: </p>
  
  <pre><code>ConversionNotSupportedException: failed to convert 'java.lang.string' to 'someCompanySpecificURLForTheClass'.
  nested execption is IllegalStateException
  Cannot convert 'java.lang.string' to 'someCompanySpecificURLForTheClass' of required type: no matching editors or conversion strategy found.
  </code></pre>
  
  <p>Am I specifying the annotation value wrongly?
  Why is this happening?</p>