title: Spring Batch: dynamic or rotate writer
body: <p>I'm trying to make the next implementation.</p>
  <p>Due to size reasons,  I have to split my output file in, for example, 10k row chunks.</p>
  <p>So, I need to dump 10k in file &quot;out1.csv&quot;, the next 10k in file &quot;out2.csv&quot;, and so on.</p>
  <p>With one output file, the schema batch:chunk with reader-processor-writer is easy and direct.</p>
  <p>The output stream is opened in batch:streams XML section inside the chunk, so I avoid the
  &quot;Writer must be open before it can be written to&quot; exception.</p>
  <p>I want to make an implementation avoiding this strict and preset solution:</p>
  <pre><code>&lt;batch:chunk reader=&quot;reader&quot;  writer=&quot;compositeWriter&quot; commit-interval=&quot;10000&quot; processor-transactional=&quot;false&quot;&gt;
      &lt;batch:streams&gt;
          &lt;batch:stream ref=&quot;writer1&quot; /&gt;
          &lt;batch:stream ref=&quot;writer2&quot; /&gt;
          &lt;batch:stream ref=&quot;writer3&quot; /&gt;
          .
          .
          .&lt;batch:stream ref=&quot;writer20&quot; /&gt;
      &lt;/batch:streams&gt;
  &lt;/batch:chunk&gt;
  
  &lt;bean id=&quot;writer1&quot; class=&quot;org.springframework.batch.item.file.FlatFileItemWriter&quot; scope=&quot;step&quot;&gt;
          &lt;property name=&quot;resource&quot; value=&quot;out1.csv&quot; /&gt;
          ...
  &lt;/bean&gt;
  
  &lt;bean id=&quot;writer2&quot; class=&quot;org.springframework.batch.item.file.FlatFileItemWriter&quot; scope=&quot;step&quot;&gt;
          &lt;property name=&quot;resource&quot; value=&quot;out2.csv&quot; /&gt;
          ...
  &lt;/bean&gt;
  
  ...
  &lt;!-- writer 20 --&gt;
  </code></pre>
  <p>Supposing that 20 writers are quite enough.
  I'm looking for a solution to create output writers dynamically (maybe programatically),  open them and avoid the above exception.</p>