title: Java / Spring: "Tagging" beans in XML to get specific bean by class and tag
body: <p>I have big XML config made from several files. </p>
  
  <p>I need to get bean implementing specific interface. But there are several implementations so I have to choose. I want to tag bean with special "tag" to get it easily:</p>
  
  <pre><code>&lt;bean class="myInterfaceImpl1" tag="beanForMe" /&gt;
  &lt;bean class="myInterfaceImpl2" /&gt;
  &lt;bean class="myInterfaceImpl3" /&gt;
  
  T get(Class&lt;T&gt; clazz) {
      return factory.getBean(clazz, "beanForMe"); //Returns first one 
  }
  </code></pre>
  
  <p>Does there is something like that in spring?</p>
  
  <p>I found 2 workaround. First is to use special tag id: </p>
  
  <p><strong>first</strong></p>
  
  <pre><code>&lt;bean class="myInterfaceImpl1" id="MyInterface-beanForMe" /&gt;
  </code></pre>
  
  <p>But when I rename class in My IDE everything would fail unless I write IDE plugin to support my idea. </p>
  
  <p><strong>Second</strong> is to add all "tagged" beans to specific list, get it by id and then iterate through it to find appropriate bean.</p>
  
  <p>But tags would be the best here. What do you think?</p>