重试不适用于Java Config的Spring Batch [英] Retry not working with Spring Batch with Java Config
问题描述
我的Spring批处理作业具有以下配置:
I have Spring batch job with following config:
@Bean
public Job myJob(Step step1, Step step2, Step step3) {
return jobs.get("myJob").start(step1).next(step2).next(step3).build();
}
@Bean
public Step step1(ItemReader<String> myReader,
ItemProcessor<String, String> myProcessor,
ItemWriter<String> myWriter) {
return steps.get("step1").<String, String>chunk(1)
.reader(myReader)
.faultTolerant().retryLimit(3).retry(MyException.class)
.processor(myProcessor)
.writer(myWriter)
.build();
}
@Bean
@StepScope
public MyReader myReader() {
return new MyReader();
}
@Bean
public MyProcessor myProcessor() {
return new MyProcessor();
}
@Bean
public MyWriter myWriter() {
return new MyWriter();
}
当MyReader类抛出MyException时,它将停止执行作业,而不会重试以下堆栈跟踪:
When MyReader class throws MyException it is stopping the execution of the job without retrying with following stack trace:
2019-05-16 14:45:09.460 ERROR 22485 --- [ main] o.s.batch.core.step.AbstractStep : Encountered an error executing step step1 in job myJob
org.springframework.batch.core.step.skip.NonSkippableReadException: Non-skippable exception during read
at org.springframework.batch.core.step.item.FaultTolerantChunkProvider.read(FaultTolerantChunkProvider.java:105) ~[spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:116) ~[spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
推荐答案
当MyReader类抛出MyException时,它将在不重试的情况下停止执行作业
When MyReader class throws MyException it is stopping the execution of the job without retrying
重试策略不适用于项目阅读器.因此,即使您将异常声明为可重试并且从读取器抛出该异常,重试策略也不会被调用.
The retry policy is not applied to the item reader. So even if you declare an exception as retryable and that exception is thrown from the reader, the retry policy is not invoked.
重试策略仅适用于处理器和写入器.
The retry policy is only applied to the processor and writer.
这篇关于重试不适用于Java Config的Spring Batch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!