title: How to execute multiple spring batch steps inside a single job
body: <pre><code>@Qualifier(&quot;billingJob&quot;)
  @Bean
  public Job billingJob(@Qualifier(&quot;fetchAgreementTasklet&quot;)Step fetchAgreementTasklet,
  @Qualifier(&quot;fetchAgreementRecurringItemsTasklet&quot;) Step fetchAgreementRecurringItemsTasklet,
  @Qualifier(&quot;fetchItemsHistoryTasklet&quot;) Step fetchItemsHistoryTasklet ,
  @Qualifier(&quot;populateAgreementStep&quot;) Step populateAgreementStep,
  @Qualifier(&quot;populateRecurringItemStep&quot;) Step populateRecurringItemStep ,
  @Qualifier(&quot;populateRecurringItemHistoryStep&quot;) Step populateRecurringItemHistoryStep ) {
          
    return jobsBuilderFactory.get(&quot;billingJob&quot;)                                
             .incrementer(new RunIdIncrementer())
             .flow(fetchAgreementTasklet)
             .next(fetchAgreementRecurringItemsTasklet)
             .next(fetchItemsHistoryTasklet)
                  
             .next(populateAgreementStep).next(populateRecurringItemStep)
             .next(populateRecurringItemHistoryStep)
             .end().build();
  }
  
      @Qualifier(&quot;populateRecurringItemStep&quot;)
      @Bean
      public Step populateRecurringItemStep(
      @Qualifier(&quot;recurringItemReader&quot;) ItemReader&lt;RecurringItemRaw&gt; recurringItemReader,
      @Qualifier(&quot;recurringItemProcessor&quot;) ItemProcessor&lt;RecurringItemRaw, RecurringItem&gt; recurringItemProcessor,
      @Qualifier(&quot;recurringItemWriter&quot;) ItemWriter&lt;RecurringItem&gt; recurringItemWriter) {
         return stepBuilderFactory.get(&quot;populateRecurringItemStep&quot;)
          .&lt;RecurringItemRaw, RecurringItem&gt; chunk(10)
          .reader(recurringItemReader).processor(recurringItemProcessor)
          .writer(recurringItemWriter).build();
      } 
  
  @Qualifier(&quot;recurringItemReader&quot;)
  @Bean
  public ItemReader&lt;RecurringItemRaw&gt; recurringItemReader() {
  FlatFileItemReader&lt;RecurringItemRaw&gt; reader = new FlatFileItemReader&lt;RecurringItemRaw&gt;();
  String file = salesforceConfiguration       .getFileLocation(SalesforceConfiguration.TYPE_AGREEMENT_ITEMS);
      LOG.info(&quot;::::::: Reading RecurringItem File ::::::: &quot; + file);
      reader.setResource(new FileSystemResource(file));
      reader.setLinesToSkip(1);
      reader.setLineMapper(new DefaultLineMapper&lt;RecurringItemRaw&gt;() {
          {
              setLineTokenizer(new DelimitedLineTokenizer() {
                  {
                      setNames(new String[] { &quot;id&quot;, &quot;name&quot;, &quot;agreementId&quot;,
                              &quot;cost&quot;, &quot;quantity&quot; });
                  }
              });
              setFieldSetMapper(new BeanWrapperFieldSetMapper&lt;RecurringItemRaw&gt;() {
                  {
                      setTargetType(RecurringItemRaw.class);
                  }
              });
          }
      });
      return reader;
  }
  
  @Qualifier(&quot;recurringItemProcessor&quot;)
  @Bean
  public ItemProcessor&lt;RecurringItemRaw, RecurringItem&gt; recurringItemprocessor() {
  return new RecurringItemProcessor();
  }
  
  @Qualifier(&quot;recurringItemWriter&quot;)
  @Bean
  public ItemWriter&lt;RecurringItem&gt; recurringItemWriter(DataSource dataSource) {
  JdbcBatchItemWriter&lt;RecurringItem&gt; writer = new JdbcBatchItemWriter&lt;RecurringItem&gt;();
  writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider&lt;RecurringItem&gt;());
  writer.setSql(PostgresqlDBQuery.INSERT_RECURRING_ITEM_QRY);
  writer.setDataSource(dataSource);
  return writer;
  }
  </code></pre>
  <p>recurringItemprocessor() is used to convert the string values to other formats</p>
  <p>recurringItemWriter() is used to insert record into my postgresql database</p>
  <p>recurringItemReader() is used to read the csv file.</p>
  <hr />
  <p>This is the processor class</p>
  <pre><code>public class RecurringItemProcessor implements ItemProcessor&lt;RecurringItemRaw, RecurringItem&gt; {
      
      private static final Logger LOG = Logger.getLogger(RecurringItemProcessor.class.getName());
  
      @Override
      public RecurringItem process(final RecurringItemRaw recurringItemRaw) throws Exception {
          LOG.info(&quot;Processing recurring item&quot;);
          final RecurringItem item = new RecurringItem(); 
          item.setId(recurringItemRaw.getId());
          item.setName(recurringItemRaw.getName());
          item.setAgreementId(recurringItemRaw.getAgreementId());
          if (recurringItemRaw.getCost().trim().isEmpty()){
              item.setCost(BigDecimal.ZERO);
          }
          else{
              item.setCost(new BigDecimal(recurringItemRaw.getCost())); 
          }
          if (recurringItemRaw.getQuantity().trim().isEmpty()){
              item.setQuantity(0);
          }else{
              item.setQuantity(new BigDecimal(recurringItemRaw.getQuantity()).intValue());
          }
          LOG.info(item.toString());
          return item;
      }
  
  }
  </code></pre>
  <hr />
  <p>I'm having issue with &quot;populateRecurringItemStep&quot; where this step running in a endloop.
  How to fix this issue ..
  I'm using the spring boot no xml configurations ..</p>