title: injecting properties to different instances of same class (Spring Framework)
body: <p>"Do mark it duplicate if required but please leave a solution link in the comments."<br/>
  I have a class "Assignment22.Player.java" of which I have to create 5 instances and inject properties to them. I can inject properties to the instances by hard coding them in the XML file itself. But I want to do that in such a manner that I do not have to go to the XML file to change the properties in case there is some "change" requirement in the future. That can be achieved using one/more properties file. <br>
  Here is what I tried to do: <br>
  I created five properties file for five different instances. But, since, the class is same hence the properties' names for every object will be same. So seemingly, I can't use the properties files this way. <br>
  here is the xml code that I tried: <br></p>
  
  <pre><code>  &lt;!-- country bean  --&gt;
    &lt;bean id = "country1" class="Assignmetn22.Country"&gt;
      &lt;property name= "countryId" value="${countryId}"&gt;&lt;/property&gt;
      &lt;property name= "countryName" value="${countryName}"&gt;&lt;/property&gt;
    &lt;/bean&gt;
    &lt;bean id = "country2" class="Assignmetn22.Country"&gt;
     &lt;!-- since the properties' names are same there won't any effect if assign them different values 
    and use them for different beans.
     --&gt;
   &lt;/bean&gt;
  
  
   &lt;bean id = "player1" class="Assignment22.Player"&gt;
     &lt;property name="playerId"  value="${playerId}"&gt;&lt;/property&gt;
     &lt;property name="playerName" value="${playrName}"&gt;&lt;/property&gt;
     &lt;property name="country" ref="country1"&gt;&lt;/property&gt;
   &lt;/bean&gt;
  
   &lt;bean id = "player2" class="Assignment22.Player"&gt;
     &lt;!-- same properties' names for other bean --&gt;
     &lt;!-- since the properties' names are same there won't any effect if assign them different values 
    and use them for different beans.
     --&gt;
     &lt;!--   &lt;property name="playerId"  value="${playerId}"&gt;&lt;/property&gt;
            &lt;property name="playerName" value="${playrName}"&gt;&lt;/property&gt;
            &lt;property name="country" ref="country2"&gt;&lt;/property&gt;
      --&gt;
    &lt;/bean&gt;
  
  
    &lt;!--loading the properties file--&gt;
      &lt;bean id= "placeholderConfig1" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
       &lt;property name="location"  value="classpath:p1.properties"&gt;&lt;/property&gt;
     &lt;/bean&gt;
     &lt;bean id= "placeholderConfig2" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
      &lt;property name="location"  value="classpath:p2.properties"&gt;&lt;/property&gt;
    &lt;/bean&gt;
     &lt;bean id= "placeholderConfig3" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
      &lt;property name="location"  value="classpath:p3.properties"&gt;&lt;/property&gt;
     &lt;/bean&gt;
    &lt;bean id= "placeholderConfig4" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
      &lt;property name="location"  value="classpath:p4.properties"&gt;&lt;/property&gt;
   &lt;/bean&gt;
   &lt;bean id= "placeholderConfig5" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
     &lt;property name="location"  value="classpath:p5.properties"&gt;&lt;/property&gt;
    &lt;/bean&gt;
  </code></pre>
  
  <p>I need to know how can I inject different properties values to different beans of same reference type (that have same properties' names) dynamically. I do not want to hard code them using XML. Is there any java way? please explain.</p>