How to create dynamic steps in Spring Batch

We can create steps dynamically and return the job reference. Here is an example -

@Bean
public Job job() {
    Step[] stepsArray = // create your steps array or pass it as a parameter
    SimpleJobBuilder jobBuilder = jobBuilderFactory.get("mainCalculationJob")
            .incrementer(new RunIdIncrementer())
            .start(truncTableTaskletStep());
    for (Step step : stepsArray) {
        jobBuilder.next(step);
    }
    return jobBuilder.build();
}

Comments

Post a Comment

Popular posts from this blog

Right way to close HttpsURLConnetion using try with resources in java 8

Spring Boot Batch - Parallel Processing (Running Multiple Jobs Concurrently)

Git Quick Card