title: Spring -- inject 2 beans of same type
body: <p>I like constructor-based injection as it allows me to make injected fields <code>final</code>. I also like annotation driven injection as it simplifies my <code>context.xml</code>. I can mark my constructor with <code>@Autowired</code> and everything works fine, as long as I don't have two parameters of the same type. For example, I have a class:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Component
  public class SomeClass {
      @Autowired(required=true)
      public SomeClass(OtherClass bean1, OtherClass bean2) {
          …
      }
  }
  </code></pre>
  
  <p>and an application context with:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;bean id="bean1" class="OtherClass" /&gt;
  &lt;bean id="bean2" class="OtherClass" /&gt;
  </code></pre>
  
  <p>There should be a way to specify the bean ID on the constructor of the class <code>SomeClass</code>, but I can't find it in the documentation.  Is it possible, or am I dreaming of a solution that does not exist yet?</p>