title: How to create dynamic steps in Spring Batch
body: <p>I need to create 'N' number of steps, depending on the 'maxHierLevel value received from the database and execute them sequentially - </p>
  
  <pre><code>int maxHierLevel = testService.getHighestLevel(); 
  
  Step masterCalculationStep = stepBuilderFactory.get("CALCUL_STEP_1")
          .&lt;Map&lt;Long, List&lt;CostCalculation&gt;&gt;, List&lt;TempCostCalc&gt;&gt;chunk(1)
          .reader(reader)
          .processor(processor)
          .writer(writer)
          .build();
  
  final Step[] stepsArray = new Step[maxHierLevel];
  
  for (int i = 0; i &lt; stepsArray.length; i++) {
      stepsArray [i] = stepBuilderFactory.get("processingRecordsInLevel_"+i)
              .partitioner("partitionningSlavStep_"+i , calculationPartioner(i))
              .step(masterCalculationStep)
              .listener(new StepResultListener())
              .taskExecutor(taskExecutor)
              .build();
  }
  
  return jobBuilderFactory.get("mainCalculationJob")
                  .incrementer(new RunIdIncrementer())
                  .flow(truncTableTaskletStep())
                  .next(loadPlantList)
                  .next(stepsArray[0]) 
                  .next(stepsArray[1])
                  .next(stepsArray[2])
                  .end()
                  .listener(listener)
                  .build();
  </code></pre>
  
  <p>can we dynamically adds steps like next(stepsArray[0]) and return job ref ?</p>