Multiple itemwriters in Spring batch

Pratik Shelar picture Pratik Shelar · Sep 20, 2013 · Viewed 38.6k times · Source

I am currently writing a Spring batch where I am reading a chunk of data, processing it and then I wish to pass this data to 2 writers. One writer would simply update the database whereas the second writer will write to a csv file.

I am planning to write my own custom writer and inject the two itemWriters in the customItemWriter and call the write methods of both the item writers in the write method of customItemWriter. Is this approach correct? Are there any ItemWriter implementations available which meet my requirements?

Thanks in advance

Answer

Oussama Zoghlami picture Oussama Zoghlami · Sep 20, 2013

You can use Spring's CompositeItemWriter and delegate to it all your writers.
here is a configuration example.