title: How to create multiple beans of same type according to configuration in Spring?
body: <p>I'm trying to create a specified number of beans of a same type in Spring.</p>
  
  <p>I've tried:</p>
  
  <pre><code>@Bean(name = "beanList")
  public List&lt;MyBean&gt; beanList(
          @Value("${number:1}") int number
          ) {
      List&lt;MyBean&gt; beanList = new ArrayList&lt;&gt;(number);
      for (int i = 0; i &lt; number; i++) {
          beanList.add(new MyBean());
      }
      return beanList;
  }
  </code></pre>
  
  <p>But this is not what expected. </p>
  
  <p>In this way, the bean "beanList" is maintained by spring context, instead of it's elements, so I can't <strong>specify a name and init method or destroy method for each element</strong> in the list.</p>
  
  <p>Any ideas?</p>