Locke
Locke

Reputation: 544

Spring Batch - How to retry and then skip if retry fails

So I currently have a spring batch process that has a composite skip policy implemented for a few custom exception types. So the issue that I am now running into is the fact that I don't always just want to skip when I get an exception.

For some database related exceptions I would like to retry a few times and then if it still fails move on and skip the record. Unfortunately I don't see a way to do this.

I tried implementing my own RetryPolicy but the only option for canRetry is true or false (rather than false I would like to throw my skippable exception).

So am I missing something here or is this not really functionality that spring batch has?

Thanks

Upvotes: 2

Views: 3146

Answers (1)

horex
horex

Reputation: 379

From a StepBuilderFactory, you can do that:

stepBuilder.reader(reader).writer(writer).faultTolerant().retryPolicy(retryPolicy).skipPolicy(skipPolicy).

And yes it is working. I had the same issue and after test, I see that my items are retried following my RetryPolicy and then they are skipped following my SkipPolicy.

Upvotes: 0

Related Questions