执行作业=[作业]时检测到重复的步骤[步骤2]。如果任一步骤失败,将在重新启动时再次执行这两个步骤 [英] Duplicate step [step2] detected in execution of job=[job]. If either step fails, both will be executed again on restart
本文介绍了执行作业=[作业]时检测到重复的步骤[步骤2]。如果任一步骤失败,将在重新启动时再次执行这两个步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Spring批处理决策器将进入forloop。我有以下要求。
如果Step1
执行,选中Decider()If<[2-1]THEN End Job,If"Yes"
THEN EXECUTEStep2
,如果Step2完成,则执行Decider()f"NO"
THEN END Job,If"Yes"
THEN EXECUTEStep3
。
任何指导,我们如何在批中配置?
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
Java代码
@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();
}
}
注意-由于安全限制,我无法从office工作站加载流程图:(
推荐答案
您的流定义中有错误。决策器的SUCCESS
结果分为两个不同的步骤:
.from(decider()).on("SUCCESS").to(step2())
...
.from(decider()).on("SUCCESS").to(step3())
此外,step2
中的转换定义不完整。您仅在COMPLETED
定义了从步骤2开始的转换:
.from(step2()).on("COMPLETED").to(decider())
您还应该为其他情况定义从step2
的过渡。
这篇关于执行作业=[作业]时检测到重复的步骤[步骤2]。如果任一步骤失败,将在重新启动时再次执行这两个步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文