작업 = [job] 실행에서 중복 단계 [step2]가 감지되었습니다. 두 단계 중 하나가 실패하면 다시 시작할 때 둘 다 다시 실행됩니다.

Dec 08 2020

Spring Batch 결정자가 forloop에 들어갑니다. 요구 사항은 다음과 같습니다.

경우 Step1실행 체크 결정기 (있으면) "NO"이라면, 작업을 종료 "Yes"한 다음 실행 Step2단계 2 다음 COMPLETED F () 결정기 실행되면, "NO"다음 작업을 종료하는 경우, "Yes"다음 실행 Step3.

배치에서 구성하는 방법에 대한 지침이 있습니까?

2020-12-08 11:41:11.473  INFO 16800 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step1]
step1
2020-12-08 11:41:11.493  INFO 16800 --- [           main] o.s.batch.core.step.AbstractStep         : Step: [step1] executed in 20ms
2020-12-08 11:41:11.508  INFO 16800 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step2]
step2
2020-12-08 11:41:11.513  INFO 16800 --- [           main] o.s.batch.core.step.AbstractStep         : Step: [step2] executed in 5ms
2020-12-08 11:41:11.568  INFO 16800 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Duplicate step [step2] detected in execution of job=[job]. If either step fails, both will be executed again on restart.
2020-12-08 11:41:11.571  INFO 16800 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step2]
step2
2020-12-08 11:41:11.577  INFO 16800 --- [           main] o.s.batch.core.step.AbstractStep         : Step: [step2] executed in 6ms
2020-12-08 11:41:11.585  INFO 16800 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Duplicate step [step2] detected in execution of job=[job]. If either step fails, both will be executed again on restart.
2020-12-08 11:41:11.589  INFO 16800 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step2]
step2
2020-12-08 11:41:11.594  INFO 16800 --- [           main] o.s.batch.core.step.AbstractStep         : Step: [step2] executed in 5ms
2020-12-08 11:41:11.601  INFO 16800 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Duplicate step [step2] detected in execution of job=[job]. If either step fails, both will be executed again on restart.
2020-12-08 11:41:11.604  INFO 16800 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step2]
step2
2020-12-08 11:41:11.608  INFO 16800 --- [           main] o.s.batch.core.step.AbstractStep         : Step: [step2] executed in 3ms
2020-12-08 11:41:11.616  INFO 16800 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Duplicate step [step2] detected in execution of job=[job]. If either step fails, both will be executed again on restart.
2020-12-08 11:41:11.618  INFO 16800 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step2]
step2
2020-12-08 11:41:11.623  INFO 16800 --- [           main] o.s.batch.core.step.AbstractStep         : Step: [step2] executed in 5ms
2020-12-08 11:41:11.630  INFO 16800 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Duplicate step [step2] detected in execution of job=[job]. If either step fails, both will be executed again on restart.
2020-12-08 11:41:11.634  INFO 16800 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step2]
step2
2020-12-08 11:41:11.638  INFO 16800 --- [           main] o.s.batch.core.step.AbstractStep         : Step: [step2] executed in 4ms
2020-12-08 11:41:11.646  INFO 16800 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Duplicate step [step2] detected in execution of job=[job]. If either step fails, both will be executed again on restart.
2020-12-08 11:41:11.648  INFO 16800 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step2]
step2

자바 코드

@Configuration
public class Config {
    @Autowired
    private JobBuilderFactory jobs;

    @Autowired
    private StepBuilderFactory steps;

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

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

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

    @Bean
    public Step step3() {
        return steps.get("step3")
                .tasklet((contribution, chunkContext) -> {
                    System.out.println("step3");
                    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())
                .from(decider()).on("SUCCESS").to(step2())
                .from(decider()).on("NO").end()
                .from(step2()).on("COMPLETED").to(decider())
                        .from(decider()).on("SUCCESS").to(step3())
                        .from(decider()).on("NO").end()
                .end()
                .build();
    }
}

참고-보안 제한으로 인해 사무실 워크 스테이션에서 흐름도를로드 할 수 없습니다.

답변

MahmoudBenHassine Dec 09 2020 at 18:00

흐름 정의에 버그가 있습니다. SUCCESS결정자 의 결과는 다음 두 단계로 진행됩니다.

.from(decider()).on("SUCCESS").to(step2())

...

.from(decider()).on("SUCCESS").to(step3())

또한의 전환 정의 step2가 불완전합니다. 다음에서 2 단계의 전환 만 정의했습니다 COMPLETED.

.from(step2()).on("COMPLETED").to(decider())

step2다른 경우에도 전환을 정의해야합니다 .