I am new to Spring Batch . I implemented a JobExecutionDecider
. Below is the code
@Component("customStepDecider")
@NoArgsConstructor
public class CustomStepDecider implements JobExecutionDecider {
Environment environment;
private String executeStep;
public static final String EXECUTE="EXECUTE";
public static final String SKIP="SKIP";
@Override
public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {
if(Boolean.parseBoolean(environment.getProperty(executeStep)))
return new FlowExecutionStatus(EXECUTE);
else
return new FlowExecutionStatus(SKIP);
}
public CustomStepDecider(String stepToExecute,Environment environment){
this.executeStep=stepToExecute;
this.environment=environment;}}
Below is the Flow
that calls the JobExecutionDecider
.The Environiment
is already autowired and same is passed to CustomStepDecider
@Bean(name = "customStepExecutionFlow")
public Flow customStepExecutionFlow(){
return new FlowBuilder<SimpleFlow>("customStepExecutionFlow")
.start(new CustomStepDecider("file.executeStep1",env))
.on("EXECUTE").to(step1)
.from(new CustomStepDecider("file.executeStep2",env))
.on("SKIP")
.to(new CustomStepDecider("file.if214FileGenerationStep",env))
.on("EXECUTE")
.to(step2)
.on("SKIP").end()
.build();
}
The functionality I need is the JobExecutionDecider
first looks at properties file if it is false, it should skip step execution .If it is true it should execute the step.Below are my properties file
file.executeStep1=false
file.executeStep2=true
But whenever I am running I am getting the below error
org.springframework.batch.core.job.flow.FlowExecutionException: Next state not found in flow=customStepExecutionFlow for state=customStepExecutionFlow.decision0 with exit status=SKIP
Where am I going wrong?
The error says you didn't specify the route for the case when your first
CustomStepDecider("file.executeStep1",env)
returns the"SKIP"
exit status.This should look something like
The same should be done with the other deciders.