我有一个主要的春季批处理工作,该工作有多个步骤。如果该作业由于某种原因失败,那么我需要调用另一个作业以使用失败结果更新数据库中的表。

如何配置我的批处理流程来做到这一点?

我像这样创建了一个JobExecution,但我不知道如何从任何if / else语句中调用新作业:

@Bean
    public JobExecutionListener dataListener() {
        JobCompletionNotificationListener dataNotificationListener = new JobCompletionNotificationListener(new JdbcTemplate(dataDataSource));
        dataNotificationListener.afterJob(jobExecution());
        return dataNotificationListener;
    }


@Bean
public JobExecution jobExecution() {

        JobExecution jobExecution = new JobExecution(jobExecution());

        if (jobExecution.getStatus() == BatchStatus.COMPLETED) {

            // If job completed successfully, update current job log to success


        } else if (jobExecution.getStatus() == BatchStatus.FAILED) {

            // If job failed, update current job log to failure

        }

        return jobExecution;
    }

最佳答案

您需要在实现JobExecutionListener接口的作业中添加一个侦听器类,并在检查条件public void afterJob(JobExecution jobExecution)后在jobExecution.getStatus() == BatchStatus.FAILED方法中调用逻辑。

07-24 20:17