使用JobExecutionDecider和spring boot batch

时间:2017-01-19 16:21:21

标签: spring spring-boot spring-batch

几个月前我用Spring Batch制作了一个项目。

此项目工作正常,包括JobExecutionDecider

的实现
public class BatchDecider implements JobExecutionDecider {
private static final Logger log = LoggerFactory.getLogger(BatchDecider.class);

@Autowired
ConfigurationServiceWs config;

public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {

    if (codition) {

        return new FlowExecutionStatus("AGAIN");
    } else {

        return new FlowExecutionStatus("FINISH");
    }
}

这只有Spring Batch。

现在我必须将它与Spring Boot Batch一起使用。 所有过程都正常工作,直到决策步骤。 我返回好的FlowExecutionStatus,但我不知道为什么,作业以“FAILED”状态完成。

2017-01-19 17:11:35.347 DEBUG 23056 --- [nio-8081-exec-1] o.s.b.core.job.flow.support.SimpleFlow   : Completed state=Global Job.decision0 with status=AGAIN
2017-01-19 17:11:39.074 DEBUG 23056 --- [nio-8081-exec-1] o.s.b.core.job.flow.support.SimpleFlow   : Handling state=Global Job.FAILED
2017-01-19 17:11:41.002 DEBUG 23056 --- [nio-8081-exec-1] o.s.b.core.job.flow.support.SimpleFlow   : Completed state=Global Job.FAILED with status=FAILED
2017-01-19 17:11:43.170 DEBUG 23056 --- [nio-8081-exec-1] o.s.batch.core.job.AbstractJob           : Job execution complete: JobExecution: id=0, version=1, startTime=Thu Jan 19 17:11:12 CET 2017, endTime=null, lastUpdated=Thu Jan 19 17:11:12 CET 2017, status=FAILED, exitStatus=exitCode=FAILED;exitDescription=, job=[JobInstance: id=0, version=0, Job=[Global Job]], jobParameters=[{time=1484842272108}]

有人知道为什么不工作?

谢谢!

1 个答案:

答案 0 :(得分:1)

我找到了解决方案。

我使用决策程序在我的工作上制作一个循环。

我正在使用它:

@Bean(name = "myJob")
public Job importUserJob() {
    return jobBuilderFactory.get("Global Job")
            .incrementer(new RunIdIncrementer())
            .flow(getListeDocMiseADispo())
            .next(decider).on("FINISH").end()

            .next(boucle())
            .next(decider).on("AGAIN").to(boucle())

            .end()
            .build();
}

与此同工:

@Bean(name = "myJob")
public Job importUserJob() {
    return jobBuilderFactory.get("Global Job")
            .incrementer(new RunIdIncrementer())
            .flow(getListeDocMiseADispo())
            .next(decider).on("AGAIN").to(boucle())
            .next(decider).on("FINISH").end()

            .next(boucle())
            .next(decider).on("AGAIN").to(boucle())

            .end()
            .build();
}

但我不知道为什么。 也许,Spring-boot-batch-starter更新我的批处理版本并打破它?

有人知道。