[Question] Any way to set decider first? #4359
-
| In xml based job configuration, we can set decider first like this. <job id="decisionJob1" > <decision id="decider1" decider="stepFlowDecider"> <end on="EXIT" exit-code="COMPLETED"/> <next on="*" to="job1Step1" /> </decision> <step id="job1Step1"> <tasklet ref="createFileTasklet"/> </step> </job>But when using code based job configuration, no way to start with decider. It there any way to set decider first on code based job configuration? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
| If you use SimpleJobBuilder instead of JobBuilder, you can create a JobFlowBuilder that starts with a decider. This is an example. I hope this example works for you. |
Beta Was this translation helpful? Give feedback.
-
| For questions and support requests, we started using GitHub discussions, see Getting Help. Therefore, I am moving this to a discussion. We will change it to an issue if we validate a bug or a missing feature. |
Beta Was this translation helpful? Give feedback.
-
| I agree with @acktsap , if it is possible to start a job with a decision in XML, it should be possible to do it in Java as well using the public class JobBuilder extends JobBuilderHelper<JobBuilder> { ++ public JobFlowBuilder start(JobExecutionDecider decider) { ++ return new FlowJobBuilder(this).start(decider); ++ } } public class FlowJobBuilder extends JobBuilderHelper<FlowJobBuilder> { ++ public JobFlowBuilder start(JobExecutionDecider decider) { ++ return new JobFlowBuilder(this, decider); ++ } }With that in place, we should be able to start a job flow with a decider in a consistent way as XML: @Bean public Job job(JobRepository jobRepository, JobExecutionDecider decider) { return new JobBuilder("myJob", jobRepository) .start(decider) .build()// build the fow .build(); // build the job }I will change this discussion into a feature request and move it to the issue tracker. Contributions are welcome! |
Beta Was this translation helpful? Give feedback.
I agree with @acktsap , if it is possible to start a job with a decision in XML, it should be possible to do it in Java as well using the
JobBuilderAPI. TheJobFlowBuilderalready provides a constructor to create a flow with a decider, so this feature could be implemented by adding the following two methods:public class JobBuilder extends JobBuilderHelper<JobBuilder> { ++ public JobFlowBuilder start(JobExecutionDecider decider) { ++ return new FlowJobBuilder(this).start(decider); ++ } } public class FlowJobBuilder extends JobBuilderHelper<FlowJobBuilder> { ++ public JobFlowBuilder start(JobExecutionDecider decider) { ++ return new JobFlowBuilder(this, decider); ++ } }With that i…