title: How to create a list filled with instances of a prototype bean using annotations?
body: <p>From this Q/A: <a href="https://stackoverflow.com/q/2416056/1065197">How to define a List bean in Spring?</a> I know I can define a <code>List&lt;Foo&gt; fooList</code> filled with <code>Foo</code> bean instances but using XML configuration. Here's an example:</p>
  
  <pre><code>public interface Foo {
      //methods here...
      void fooMethod();
  }
  
  @Service("foo")
  @Scope("prototype")
  public class FooImpl implements Foo {
      //fields and methods...
      @Override
      public void fooMethod() {
          //...
      }
  }
  
  @Service("fooCache")
  @Scope
  public class FooCacheImpl implements Foo {
      //fields and methods...
      @Override
      public void fooMethod() {
          //retrieves data from some cache
          //...
      }
  }
  
  @Service("fooWS")
  @Scope("prototype")
  public class FooWSImpl implements Foo {
      //fields and methods...
      @Override
      public void fooMethod() {
          //retrieves data from web service
          //...
      }
  }
  </code></pre>
  
  <p>I can configure a client through XML:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;bean id="fooClient" class="some.package.FooClient"&gt;
      &lt;property name="fooList"&gt;
          &lt;list&gt;
              &lt;bean ... /&gt; &lt;!-- This may be fooImpl --&gt;
              &lt;bean ... /&gt; &lt;!-- This may be fooCacheImpl --&gt;
              &lt;bean ... /&gt; &lt;!-- This may be fooWSImpl --&gt;
              &lt;!-- I can have more beans here --&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>I want to know if this can be done with annotations only, no need to define the bean through XML. Something like this:</p>
  
  <pre><code>@Component
  @Scope("prototype")
  public class FooClient {
      //which annotation(s) to use here to fill this list with FooImpl instances?
      //I understand that if I have two implementations of Foo I may use a @Qualifier
      //or use another list to note the different implementations.
      private List&lt;Foo&gt; fooList;
  
      public void bar() {
          for (Foo foo : fooList) {
              foo.fooMethod();
          }
      }
  }
  </code></pre>
  
  <p>I think it would be better a solution that doesn't involve injecting the <code>ApplicationContext</code> nor the <code>BeanFactory</code> so <code>FooClient</code> is not tightly coupled to Spring classes. Also, for my case, I cannot use any Java EE classes like <code>javax.inject.Provider</code> as shown in this blog post: <a href="http://benkiew.wordpress.com/2012/04/22/spring-2-5-x-create-prototype-instances-from-code/" rel="nofollow noreferrer">Spring 2.5.x+3.0.x: Create prototype instances from code</a>.</p>