You can use Skip Listener
@Component
public class CustomSkipListener {
@OnSkipInRead
public void onSkipInRead(Throwable t) {
System.out.println("From onSkipInRead -> " + t.getMessage());
}
@OnSkipInWrite
public void onSkipInWrite(String item, Throwable t) {
System.out.println("From onSkipInWrite: " + item + " -> " + t.getMessage());
}
@OnSkipInProcess
public void onSkipInProcess(String item, Throwable t) {
System.out.println("From onSkipInProcess: " + string + " -> " + t.getMessage());
}
}
Then in your step
@Bean
public Step step1(CustomSkipListener customSkipListener) {
return stepBuilderFactory
.get("step1")
.<String, String> chunk(1)
.reader(reader())
.processor(processor())
.writer(writer())
.faultTolerant()
.skipLimit(10)
.skip(RuntimeException.class)
.listener(customSkipListener)
.build();
}
Notice the CHAIN starting from .faultTolerant()
. Adding the listener is not mandatory. If you add the listener
you can handle the behaviour when skipping happens.
Some helpful links
http://docs.spring.io/spring-batch/apidocs/org/springframework/batch/core/SkipListener.html
http://docs.spring.io/spring-batch/reference/html/configureStep.html#configuringSkip