对于 FlowJobBuilder 类型,方法 next(Step) 未定义

The method next(Step) is undefined for the type FlowJobBuilder

我正在处理 Spring 引导和批处理项目并使用 spring 批处理决定器。

错误

The method next(Step) is undefined for the type FlowJobBuilder

return jobBuilderFactory.get("sampleJob")
    .incrementer(new RunIdIncrementer())
    .start(abcStep(stepBuilderFactory, abcReader))
    .next(sampleDecider())
    .from(sampleDecider())
        .on(MDSConst.SUCCESS).to(xyxStep(stepBuilderFactory, xyzReader))
    .from(sampleDecider())
        .on(MDSConst.FAILED).end().build()
    .next(mnoStep(stepBuilderFactory, mnoReder))
    .build();
  1. 如果 sampleDecider 成功,xyxStep 应该执行
  2. 如果 sampleDecider 给出 FAILED,批处理作业应该停止
  3. 如果 sampleDecider 成功,则 xyxStep 应该执行,然后 mnoStep 应该执行

我希望这是基于块的步骤的写法。

import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.job.flow.FlowExecutionStatus;
import org.springframework.batch.core.job.flow.JobExecutionDecider;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableBatchProcessing
public class MyJob {

    @Autowired
    private JobBuilderFactory jobs;

    @Autowired
    private StepBuilderFactory steps;

    @Bean
    public Step step1() {
        return steps.get("step1")
                .tasklet((contribution, chunkContext) -> {
                    System.out.println("hello");
                    return RepeatStatus.FINISHED;
                })
                .build();
    }

    @Bean
    public JobExecutionDecider decider() {
        return (jobExecution, stepExecution) -> new FlowExecutionStatus("YES"); // or NO
    }

    @Bean
    public Step step2() {
        return steps.get("step2")
                .tasklet((contribution, chunkContext) -> {
                    System.out.println("world");
                    return RepeatStatus.FINISHED;
                })
                .build();
    }

    @Bean
    public Step step3() {
        return steps.get("step3")
                .tasklet((contribution, chunkContext) -> {
                    System.out.println("!!");
                    return RepeatStatus.FINISHED;
                })
                .build();
    }
    
    
    @Bean
    public Step step5() {
        return steps.get("step5")
                .tasklet((contribution, chunkContext) -> {
                    System.out.println("Step 5");
                    return RepeatStatus.FINISHED;
                })
                .build();
    }
    
    
    @Bean
    public Step step4() {
        return steps.get("step4")
                .tasklet((contribution, chunkContext) -> {
                    System.out.println("Step 4");
                    return RepeatStatus.FINISHED;
                })
                .build();
    }

    @Bean
    public Job job() {
        return jobs.get("job")
                .incrementer(new RunIdIncrementer())
                .start(step1())
                .next(decider())
                    .on("YES").to(step2())
                    .next(step4())
                    .next(step5())
                 .from(decider())
                        .on("NO").to(step3())
                    .end()
                .build();
    }

    public static void main(String[] args) throws Exception {
        ApplicationContext context = new AnnotationConfigApplicationContext(MyJob.class);
        JobLauncher jobLauncher = context.getBean(JobLauncher.class);
        Job job = context.getBean(Job.class);
        jobLauncher.run(job, new JobParameters());
    }

}