I'm working with spring batch 4 (annotation) and have a job with one step which reads an XML file and write to a text file. I used a custom reader and a simple flat writer (spring batch reference), before reading XML. I checked if this XML is a file, and if so I process the transformation from XML to text. But if the file is not valid I return null in the reader.
The problem is that when I return null in the reader, the writer is still working and puts an empty file into the output folder. What is the solution?
@Bean public FlatFileItemWriter itemWriter() {
return
new FlatFileItemWriterBuilder<Foo>()
.name("itemWriter")
.resource(new FileSystemResource("target/test-outputs/output.txt"))
.lineAggregator(new PassThroughLineAggregator<>())
.build();
}