问题
I'm using Spring Batch with partitioning. Initially, I was getting DeadlockLoserDataAccessException and then I have configured our steps as faultTolerant, please see the following code -
Step masterCalculationStep = stepBuilderFactory.get("STEP_1")
.<Map<Long, List<CostCalculation>>, List<TempCostCalc>>chunk(1).reader(reader)
.processor(processor)
.writer(writer)
.faultTolerant()
.retryLimit(5)
.retry(DeadlockLoserDataAccessException.class)
.build();
but now we are getting another exception -
org.springframework.batch.core.step.skip.NonSkippableReadException: Non-skippable exception during read
Don't know why this new exception and how to resolve it?
回答1:
The RetryPolicy in a chunk oriented step is not applied to the reader. So if your reader might throw a transient exception, you need to add the retry logic around the reader yourself. This can be done for example with:
- AOP by applying
org.springframework.retry.interceptor.RetryOperationsInterceptorto your reader - or by using
org.springframework.retry.support.RetryTemplatein a decorator of your reader that reties thereadmethod when it throws a transient exception
Similar questions can be found here:
- Spring batch retry mechanism for reader failure
- Retry in case of a failed reading
Hope this helps.
来源:https://stackoverflow.com/questions/54902312/spring-batch-deadlockloserdataaccessexception