title: How to collect and inject all beans of a given type in Spring XML configuration
body: <p>One of the strongest accents of the Spring framework is the <a href="http://en.wikipedia.org/wiki/Dependency_injection" rel="noreferrer">Dependency Injection</a> concept. I understand one of the advices behind that is to separate general high-level mechanism from low-level details (as announced by <a href="http://en.wikipedia.org/wiki/Dependency_inversion_principle" rel="noreferrer">Dependency Inversion Principle</a>).</p>
  
  <p>Technically, that boils down to having a bean implementation to know as little as possible about a bean being injected as a dependency, e.g.</p>
  
  <pre><code>public class PrintOutBean {
      private LogicBean logicBean;
      public void action() {
          System.out.println(logicBean.humanReadableDetails());
      }
      //...
  }
  
  &lt;bean class="PrintOutBean"&gt;
      &lt;property name="loginBean" ref="ShoppingCartBean"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>But what if I wanted to a have a high-level mechanism operating on multiple dependent beans? </p>
  
  <pre><code>  public class MenuManagementBean {
         private Collection&lt;Option&gt; options;
         public void printOut() {
              for (Option option:options) {
                // do something for option
              }
              //...
         }
    }
  </code></pre>
  
  <p>I know one solution would be to use <code>@Autowired</code> annotation in the singleton bean, that is...</p>
  
  <pre><code>  @Autowired
    private Collection&lt;Option&gt; options;
  </code></pre>
  
  <p>But doesn't it violate the separation principle? Why do I have to specify what dependents to take in the very same place I use them (i.e. <code>MenuManagementBean</code> class in my example)? 
  Is there a way to inject collections of beans in the XML configuration like this (without any annotation in the <code>MMB</code> class)?</p>
  
  <pre><code>&lt;bean class="MenuManagementBean"&gt;
      &lt;property name="options"&gt;
         &lt;xxx:autowire by-type="MyOptionImpl"/&gt;
      &lt;/property&gt;
   &lt;/bean&gt;
  </code></pre>