我正在使用具有多个流的Spring Batch流程,在某些流程中使用最佳步骤,我正在做的流程是: Flow
我尝试过多种形式,如果你在JobExecutionDecider之后输入相应流程的第一步,但它在流程的第一步进入循环。
我的JobExecutionDecider返回第一步(S1)中的gnerated状态:
S1:
public class ProductWMExportTasklet extends ProductExportHelper implements Tasklet{
private static final Logger LOGGER = LoggerFactory.getLogger(ProductWMExportTasklet.class);
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
ExecutionContext stepContext = chunkContext.getStepContext()
.getStepExecution()
.getJobExecution()
.getExecutionContext();
//for example for the flow NOBASIC
stepContext.put(ProductWMExportFlowDecision.KEY_BASIC_NOBASIC_FLOW, ProductWMExportFlowDecision.NOBASIC);
return RepeatStatus.FINISHED ;
}
}
和我的JobExecutionDecider:
public class ProductWMExportFlowDecision implements JobExecutionDecider{
public static final String KEY_BASIC_NOBASIC_FLOW = "KEY_BASIC_NOBASIC_FLOW";
public static final String BASIC_TXT = "BASIC_TXT";
public static final String BASIC_IMG = "BASIC_IMG";
public static final String BASIC_TXT_IMG = "BASIC_TXT_IMG";
public static final String NOBASIC = "NOBASIC";
public static final String SEND_TIBCO_KEY = "SEND_TIBCO_KEY";
public static final String IS_FULL_KEY = "IS_FULL_KEY";
public static final String BASIC_FILE_KEY = "BASIC_FILE_KEY";
@Override
public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {
System.out.println("llave enviada:"+stepExecution.getJobExecution().getExecutionContext().get(KEY_BASIC_NOBASIC_FLOW));
return new FlowExecutionStatus((String) stepExecution.getJobExecution().getExecutionContext().get(KEY_BASIC_NOBASIC_FLOW));
}}
我尝试过两种不同的方法:
public Job productWMExportJob() {
FlowBuilder<Flow> flowBuilderTxt = new FlowBuilder<Flow>(ProductWMExportFlowDecision.BASIC_TXT);
FlowBuilder<Flow> flowBuilderImg = new FlowBuilder<Flow>(ProductWMExportFlowDecision.BASIC_IMG);
FlowBuilder<Flow> flowBuilderTxtImg = new FlowBuilder<Flow>(ProductWMExportFlowDecision.BASIC_TXT_IMG);
FlowBuilder<Flow> flowBuilderNoBasic = new FlowBuilder<Flow>(ProductWMExportFlowDecision.NOBASIC);
Flow flowBasicTxt = flowBuilderTxt
.start(S2())
.next(S3()).build();
Flow flowBasicImg = flowBuilderImg
.start(S2())
.next(S4()).next(S5()).build();
Flow flowBasicTxtImg = flowBuilderTxtImg
.start(S2())
.next(S3())
.next(S4()).next(S5()).build();
Flow flowBasicNoBasic = flowBuilderNoBasic
.start(S3())
.next(S4()).next(S5()).build();
return jobBuilderFactory.get("productWMExportJob").listener(jobStatisticsPrintListener)
.incrementer(new RunIdIncrementer())
.start(S1())
.next(decision())
.on(ProductWMExportFlowDecision.BASIC_TXT)
.to(flowBasicTxt)
.from(decision())
.on(ProductWMExportFlowDecision.BASIC_IMG)
.to(flowBasicImg)
.from(decision())
.on(ProductWMExportFlowDecision.BASIC_TXT_IMG)
.to(flowBasicTxtImg)
.from(decision())
.on(ProductWMExportFlowDecision.NOBASIC)
.to(flowBasicNoBasic)
.end().build();}
和
public Job productWMExportJob() {
return jobBuilderFactory.get("productWMExportJob").listener(jobStatisticsPrintListener).incrementer(new RunIdIncrementer()).
flow(S1())
.next(decision())
.on(ProductWMExportFlowDecision.BASIC_TXT)
.to(S2()).next(S3())
.from(decision())
.on(ProductWMExportFlowDecision.BASIC_IMG)
.to(S2()).next(S4()).next(S5())
.from(decision())
.on(ProductWMExportFlowDecision.BASIC_TXT_IMG)
.to(S2()).next(S3()).next(S4()).next(S5())
.from(decision())
.on(ProductWMExportFlowDecision.NOBASIC)
.to(S3()).next(S4()).next(S5())
.end().build();}
我希望有人可以帮助我创造这种流程。