java - 使用面向 block 的处理在 Spring 批量远程分块中实现 SkippableTasklet

标签 java spring spring-batch

我目前正在使用 Spring Batch,并且想要使用远程分块。

我使用面向 block 的处理,使用项目读取器、项目处理器和项目写入器,并希望实现跳过。

我读过这个question这告诉我创建 SkippableTasklet 但我有点困惑如何实现 protected abstract void run(JobParameters jobParameters) throws Exception;

如何在此远程分块实现中实现跳过?

最佳答案

有几种方法可以处理可跳过的异常。 我是这样写的

<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:listeners>
        batch:listener ref="skippableListener'/>
    </batch:listeners>
</batch:step>
<bean id="skippableListener" class="SkippableListener/>

public class SkippableListener implements SkipListener
{
   void onSkipInProcess(T item, java.lang.Throwable t){
   //Write your logic
   };
   void onSkipInRead(java.lang.Throwable t){
   //Write your logic
   };
   void onSkipInWrite(S item, java.lang.Throwable t){
   //Write your logic
   };
}

关于java - 使用面向 block 的处理在 Spring 批量远程分块中实现 SkippableTasklet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47788407/

相关文章:

java - 使用 VSCode 发送电子邮件(spring-boot-starter-email)

java - Imageview 不采用卡片 View 的角半径

java - Spring Security LDAP 和记住我

spring - 执行代码时如何阻止 Spring 批处理计划作业在第一次运行?

java - PhoneGap : Remote Logging with gwt-log

java - 启动 TOMCAT 时出错

java - 有人可以帮助我在 rest-api 中使用文本文件吗?

java - @Configuration类,将@Bean传递给其他@Bean

Spring Batch ItemWriteListener 和 SkipListener 不能齐头并进

spring - 在没有 Spring Boot 的情况下创建上下文后防止 Spring Batch 自 Action 业触发