Search code examples
springspring-batchbatch-processing

Spring's MultiResourceItemWriter is not calling header and footer callback if reader returns no item


I have a job that reads from DB and creates an output file. I am using MultiResourceItemWriter so roll over the file if number of records in a file exceeds some threshold value. I have a requirement to generate empty file with (header and footer) even if reader fetches no data.

The job doesn't create file if reader fetches NO data even though the delegated FlatFileItemWriterBuilder is listening to header and footer callback.

Thanks


Solution

  • This is how that writer is designed to work, as specified in its Javadoc:

    Note that new resources are created only at chunk boundaries
    

    This means if no items are returned by the reader, no output resource will be created. If you want to customize this behaviour, you can extend that writer or create a custom one for your needs.