title: Spring Batch - Configure Tasklet in Step having reader and writer?
body: <p>I am using Spring Batch boot example. In this example, I am looking to convert XML based application into annotation based application. However I am struggling to configure using @Bean in Step to create exact configuration.</p>
  
  <pre class="lang-xml prettyprint-override"><code>    &lt;batch:step id="step1"&gt;
          &lt;batch:tasklet&gt;
              &lt;batch:chunk reader="paymentDataReader" writer="paymentDataWriter" commit-interval="100000"&gt;
                  &lt;batch:listeners&gt;
                      &lt;batch:listener ref="paymentingStepExecutionListener" /&gt;
                  &lt;/batch:listeners&gt;
              &lt;/batch:chunk&gt;
          &lt;/batch:tasklet&gt;
          &lt;batch:next on="COMPLETED" to="sendpaymentingBatchFiles" /&gt;
      &lt;/batch:step&gt;
  </code></pre>
  
  <p>JobConfiguration.java</p>
  
  <pre class="lang-java prettyprint-override"><code>    @Configuration
      public class JobConfiguration {
          @Autowired
          private JobBuilderFactory jobBuilderFactory;
  
          @Autowired
          private StepBuilderFactory stepBuilderFactory;
  
          @Autowired
          private DataSource dataSource;
  
          @Bean
          @StepScope
          public PaymentContextTasklet paymentContextTasklet() {
              return new PaymentContextTasklet();
          }
  
          // Either execute for "Payment" or "Order"
          @Bean
          public ContextDecider contextDecider() {
              return new ContextDecider();
          }
  
          @Bean
          public JdbcPagingItemReader&lt;Payment&gt; pagingItemReader(){
              JdbcPagingItemReader&lt;Payment&gt; reader = new JdbcPagingItemReader&lt;&gt;();
              reader.setDataSource(this.dataSource);
              reader.setFetchSize(10);
              reader.setRowMapper(new PaymentRowMapper());
  
              MySqlPagingQueryProvider queryProvider = new MySqlPagingQueryProvider();
              queryProvider.setSelectClause("select paymentId, amount, customerId, paymentDate");
              queryProvider.setFromClause("from payment");
  
              reader.setQueryProvider(queryProvider);
              return reader;
          }
  
          @Bean
          public ItemWriter&lt;Payment&gt; paymentItemWriter(){
              return items -&gt; {
                  for(Payment c : items) {
                      System.out.println(c.toString());
                  }
              };
          }
  
          @Bean
          public PaymentStepExecutionListener paymentStepExecutionListener() {
              return new PaymentStepExecutionListener();
          }
  
          @Bean
          public Step step1() {
              return stepBuilderFactory.get("step1")
                      .&lt;Payment, Payment&gt;chunk(10)
                      .reader(pagingItemReader())
                      .writer(paymentItemWriter())
                      .tasklet(paymentStepExecutionListener())
                      .rea
                      .build();
          }
  
          @Bean
          @StepScope
          public PaymentDataTasklet paymentDataTasklet() {
              return new PaymentDataTasklet();
          }
  
          @Bean
          public Step paymentContextStep() {
              return stepBuilderFactory.get("paymentContextStep")
                      .tasklet(paymentContextTasklet())
                      .build();
          }
  
          @Bean
          public Step paymentDataStep() {
              return stepBuilderFactory.get("paymentDataStep")
                      .tasklet(paymentDataTasklet())
                      .build();
          }
  
          @Bean
          public Step endStep() {
              return stepBuilderFactory.get("endStep")
                      .tasklet(null)
                      .build();
          }
  
          @Bean
          public Job paymentDataBatchJob() {
              return jobBuilderFactory.get("paymentDataBatchJob")
                      .start(paymentContextStep())
                      .next(contextDecider())
                          .on("Payment").to(paymentDataStep()).on("COMPLETED").to(endStep)
                      .from(contextDecider())
                          .on("Order").to(endStep()).end()
                      .build();
          }
      }
  </code></pre>