I am new to Spring batch.
I have to read multiple files(delimiter) from a folder and load them in DB. Which I did.
But my issue is after each file is processed I have to move the file to processed folder or error records to Error folder.
For example if I process a below file (abc.txt) from multiple file:
D|hello1|123
D|hello2|three - Error
D|hello3|123
I know that 2nd record is an error.
Now I have to write the error record in a error file(abc-error.txt) to error folder and proceed with the next record. After the file is processed successfully excluding error records, i need to move the abc.txt to a processed folder.
How can I achieve the above requirement?
My job:
<batch:job id="file_to_db">
<batch:step id="step1">
<batch:tasklet ref="moveFiletoTmpFolder" />
<batch:end on="FAILED"/>
<batch:next on="*" to="step2" />
</batch:step>
<batch:step id="step2">
<batch:tasklet transaction-manager="transactionManager"
start-limit="100">
<batch:chunk reader="multiResourceReader" writer="databaseItemWriter"
commit-interval="100">
</batch:chunk>
</batch:tasklet>
</batch:step>
</batch:job>
<bean id="multiResourceReader"
class=" org.springframework.batch.item.file.MultiResourceItemReader">
<property name="resources" value="file:batch/csv/processing/*.csv" />
<property name="delegate" ref="cvsFileItemReader" />
</bean>
The job is not one step. But each file must be moved once it is processed.
Error records must be written into a separate file named filename-error.txt for each file.