Reputation: 5787
In a particular spring-batch job, I am using a Flow
(as it is a reusable sequence of steps) as a Step
.
I have to pass a set of parameters to the Flow
.
How do I do that?
My job definition is as follows:
@Component
public class MyJob {
@Bean
public Job myJob(@Qualifier("myFlowStep") Flow myFlow) {
return jobBuilderFactory.get("myJob").incrementer(new RunIdIncrementer())
.start(someFirstStep())
.next(myFlowStep(myFlow)).
.build();
}
...
@Bean
public Step myFlowStep(Flow myFlow) {
// Need to pass parameters to the flow
FlowStepBuilder flowStepBuilder = stepBuilderFactory.get("myFlowStep").flow(myFlow);
return flowStepBuilder.build();
}
...
}
Upvotes: 0
Views: 1843
Reputation: 31600
You can make the flow bean definition step scoped and use late-binding of job parameters:
@Bean
@StepScope
public Flow myFlow(@Value("#{jobParameters['name']}") String name) {
// use job parameter name here
return null;
}
@Bean
public Step myFlowStep(Flow myFlow) {
// Need to pass parameters to the flow
FlowStepBuilder flowStepBuilder = stepBuilderFactory.get("myFlowStep").flow(myFlow);
return flowStepBuilder.build();
}
Upvotes: 1