I have a Spring Batch job that needs to do the below
- Check a directory on local file system that may contain more than one file
- Process each of the files, save data from those files to database
- Rename files by adding a suffix to include PROCESSED or ERROR
I have used the below
- A MultiResourceItemReader that reads files and delegates to a FlatFileItemReader
- The FlatFileItemReader reads data using LineMapper, FieldSetMapper
- An ItemProcessor manipulates data read
- An ItemWriter writes to the database
What I want to do
- Rename each file to either PROCESSED / ERROR at the end of Step based on execution status
- How do I pass the resource file name that the FlatFileItemReader processes to the StepExecutionListener?
- How do I pass the resource file name to the ItemProcessor as it also needs to save the name of the file the data was read from
Below is my relevant config
<batch:job id="myJob" job-repository="jobRepository">
<batch:step id="processFiles">
<batch:tasklet>
<batch:chunk reader="multiResourceReader" processor="myItemProcessor" writer="myItemWriter" commit-interval="100" />
</batch:tasklet>
<batch:listeners>
<batch:listener ref="myStepListener"/>
</batch:listeners>
</batch:step>
</batch:job>