title: spring batch 3 ItemReader reading CSV file data only one time
body: <p>Hi I am new to Spring Batch and I referred <a href="http://www.concretepage.com/spring-batch-3/spring-batch-3-annotation-example-using-mysql-gradle" rel="nofollow">this link</a> to run the sample program. </p>
  
  <p>I wanted to insert the large amount of CSV file data into MySQL database and through the example I am able to execute it fine with limited number of lines of CSV data.</p>
  
  <p>But when I inserted more number of lines into CSV file and execute the batch program it was not inserting any data in other words it was not reading the file itself and not even showing any error/exception(s). I think I need to configure <code>ItemReader</code> to read for more than one time. </p>
  
  <p>Following is the BatchConfiguration.java code</p>
  
  <pre><code> @Configuration
  @EnableBatchProcessing
  public class BatchConfiguration {
  
      @Bean
      public ItemReader&lt;Student&gt; reader() {
          FlatFileItemReader&lt;Student&gt; reader = new FlatFileItemReader&lt;Student&gt;();
          reader.setResource(new ClassPathResource("student-data.csv"));
          reader.setLineMapper(new DefaultLineMapper&lt;Student&gt;() {{
              setLineTokenizer(new DelimitedLineTokenizer() {{
                  setNames(new String[] {"stdId", "subMarkOne", "subMarkTwo" });
              }});
              setFieldSetMapper(new BeanWrapperFieldSetMapper&lt;Student&gt;() {{
                  setTargetType(Student.class);
              }});
          }});
          return reader;
      }
  
  
      @Bean
      public ItemWriter&lt;Marksheet&gt; writer(DataSource dataSource) {
          JdbcBatchItemWriter&lt;Marksheet&gt; writer = new JdbcBatchItemWriter&lt;Marksheet&gt;();
          writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider&lt;Marksheet&gt;());
          writer.setSql("INSERT INTO marksheet (studentId,totalMark) VALUES (:stdId,:totalSubMark)");
          writer.setDataSource(dataSource);
          return writer;
      }
  
      @Bean
      public ItemProcessor&lt;Student, Marksheet&gt; processor() {
          return new StudentItemProcessor();
      }
  
      @Bean
      public Job createMarkSheet(JobBuilderFactory jobs, Step step) {
          return jobs.get("createMarkSheet")
                  .flow(step)
                  .end()
                  .build();
      }
  
      @Bean
      public Step step(StepBuilderFactory stepBuilderFactory, ItemReader&lt;Student&gt; reader,
              ItemWriter&lt;Marksheet&gt; writer, ItemProcessor&lt;Student, Marksheet&gt; processor) {
          return stepBuilderFactory.get("step")
                  .&lt;Student, Marksheet&gt; chunk(5)
                  .reader(reader)
                  .processor(processor)
                  .writer(writer)
                  .build();
      }
  
      @Bean
      public JdbcTemplate jdbcTemplate(DataSource dataSource) {
          return new JdbcTemplate(dataSource);
      }
  
      @Bean
      public DataSource getDataSource() {
          BasicDataSource dataSource = new BasicDataSource();
          dataSource.setDriverClassName("com.mysql.jdbc.Driver");
          dataSource.setUrl("jdbc:mysql://localhost:3306/concretepage");
          dataSource.setUsername("root");
          dataSource.setPassword("root123");
          return dataSource;
      }
  </code></pre>
  
  <p>main class to run </p>
  
  <pre><code>@ComponentScan
  @EnableAutoConfiguration
  public class Main {
      public static void main(String[] args) {
          ApplicationContext ctx = SpringApplication.run(Main.class, args);
          List&lt;Marksheet&gt; result = ctx.getBean(JdbcTemplate.class).query("select studentId,totalMark FROM marksheet", 
                  new RowMapper&lt;Marksheet&gt;() {
              @Override
              public Marksheet mapRow(ResultSet rs, int row) throws SQLException {
                  return new Marksheet(rs.getString(1), Integer.parseInt(rs.getString(2)));
              }
          });
          System.out.println("Number of Record:"+result.size());
      }
  }
  </code></pre>
  
  <p>process class</p>
  
  <pre><code>public class StudentItemProcessor implements ItemProcessor&lt;Student, Marksheet&gt; {
  
      @Override
      public Marksheet process(final Student student) throws Exception {
          int totalMark = student.getSubMarkOne()+student.getSubMarkTwo();
          System.out.println("student id:"+student.getStdId() +" and Total mark:"+ totalMark);
          Marksheet marksheet = new Marksheet(student.getStdId(), totalMark);
          return marksheet;
      }
  
  }
  </code></pre>
  
  <p>Any help will be appreciated. thanks. </p>