大佬教程收集整理的这篇文章主要介绍了Spring Batch-TaskletStep中的可跳过异常,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
正如Michael minella建议的那样,我在tasklet中实现了此功能:
abstract class Skippabletasklet implements tasklet {
//Exceptions that should not cause job status to be BatchStatus.Failed
private List<Class<?>> skippableExceptions;
public voID setSkippableExceptions(List<Class<?>> skippableExceptions) {
this.skippableExceptions = skippableExceptions;
}
private Boolean isSkippable(Exception E) {
if (skippableExceptions == null) {
return false;
}
for (Class<?> c : skippableExceptions) {
if (e.getClass().isAssignableFrom(C)) {
return true;
}
}
return true;
}
protected abstract voID run(JobParameters jobParameters) throws Exception;
@OverrIDe
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
throws Exception {
StepExecution stepExecution = chunkContext.getStepContext().getStepExecution();
JobExecution jobExecution = stepExecution.getJobExecution();
JobParameters jobParameters = jobExecution.getJobParameters();
try {
run(prj);
} catch (Exception E) {
if (!isSkippable(E)) {
throw e;
} else {
jobExecution.addFailureException(E);
}
}
return RepeatStatus.FINISHED;
}
}
以Spring XML配置为例Skippabletasklet
:
<batch:tasklet>
<bean class="com.MySkippabletasklet" scope="step" autowire="byType">
<property name="skippableExceptions">
<List>
<value>org.springframework.mail.MailException</value>
</List>
</property>
</bean>
</batch:tasklet>
BatchStatus.FAILED
如果发生某些异常,我试图使工作没有。
这些文档讨论的是skippable-exception-
classes
在内部使用<chunk>
,但是如何在内部使用TaskletStep
呢?以下代码不起作用:
<batch:step id="sendEmailStep">
<batch:tasklet>
<bean class="com.myproject.SendEmail" scope="step" autowire="byType">
<batch:skippable-exception-classes>
<batch:include class="org.springframework.mail.MailException" />
</batch:skippable-exception-classes>
</bean>
</batch:tasklet>
</batch:step>
以上是大佬教程为你收集整理的Spring Batch-TaskletStep中的可跳过异常全部内容,希望文章能够帮你解决Spring Batch-TaskletStep中的可跳过异常所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。