title: Spring Batch: File not being read
body: <p>I am trying to create an application that uses the spring-batch-excel extension to be able to read Excel files uploaded through a web interface by it's users in order to parse the Excel file for addresses.</p>
  
  <p>When the code runs, there is no error, but all I get is the following in my log.  Even though I have log/syso throughout my Processor and Writer (these are never being called, and all I can imagine is it's not properly reading the file, and returning no data to process/write).  And yes, the file has data, several thousand records in fact.</p>
  
  <pre><code>Job: [FlowJob: [name=excelFileJob]] launched with the following parameters: [{file=Book1.xlsx}]
  Executing step: [excelFileStep]
  Job: [FlowJob: [name=excelFileJob]] completed with the following parameters: [{file=Book1.xlsx}] and the following status: [COMPLETED]
  </code></pre>
  
  <p><strong>Below is my JobConfig</strong></p>
  
  <pre><code>@Configuration
  @EnableBatchProcessing
  public class AddressExcelJobConfig {
  
      @Bean
      public BatchConfigurer configurer(EntityManagerFactory entityManagerFactory) {
          return new CustomBatchConfigurer(entityManagerFactory);
      }
  
      @Bean
      Step excelFileStep(ItemReader&lt;AddressExcel&gt; excelAddressReader,
                         ItemProcessor&lt;AddressExcel, AddressExcel&gt; excelAddressProcessor,
                         ItemWriter&lt;AddressExcel&gt; excelAddressWriter, 
                         StepBuilderFactory stepBuilderFactory) {
          return stepBuilderFactory.get("excelFileStep")
                  .&lt;AddressExcel, AddressExcel&gt;chunk(1)
                  .reader(excelAddressReader)
                  .processor(excelAddressProcessor)
                  .writer(excelAddressWriter)
                  .build();
      }
  
      @Bean
      Job excelFileJob(JobBuilderFactory jobBuilderFactory, 
                       @Qualifier("excelFileStep") Step excelAddressStep) {
          return jobBuilderFactory.get("excelFileJob")
                  .incrementer(new RunIdIncrementer())
                  .flow(excelAddressStep)
                  .end()
                  .build();
      }
  }
  </code></pre>
  
  <p><strong>Below is my AddressExcelReader</strong>
  The late binding works fine, there is no error.  I have tried loading the resource given the file name, in addition to creating a new ClassPathResource and FileSystemResource.  All are giving me the same results.</p>
  
  <pre><code>@Component
  @StepScope
  public class AddressExcelReader implements ItemReader&lt;AddressExcel&gt; {
  
      private PoiItemReader&lt;AddressExcel&gt; itemReader = new PoiItemReader&lt;AddressExcel&gt;();
  
      @Override
      public AddressExcel read()
              throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
          return itemReader.read();
      }
  
      public AddressExcelReader(@Value("#{jobParameters['file']}") String file, StorageService storageService) {
          //Resource resource = storageService.loadAsResource(file);
          //Resource testResource = new FileSystemResource("upload-dir/Book1.xlsx");
          itemReader.setResource(new ClassPathResource("/upload-dir/Book1.xlsx"));
          itemReader.setLinesToSkip(1);
          itemReader.setStrict(true);
          itemReader.setRowMapper(excelRowMapper());
      }
  
      public RowMapper&lt;AddressExcel&gt; excelRowMapper() {
          BeanWrapperRowMapper&lt;AddressExcel&gt; rowMapper = new BeanWrapperRowMapper&lt;&gt;();
          rowMapper.setTargetType(AddressExcel.class);
          return rowMapper;
      }
  
  }
  </code></pre>
  
  <p><strong>Below is my AddressExcelProcessor</strong></p>
  
  <pre><code>@Component
  public class AddressExcelProcessor implements ItemProcessor&lt;AddressExcel, AddressExcel&gt; {
  
      private static final Logger log = LoggerFactory.getLogger(AddressExcelProcessor.class);
  
      @Override
      public AddressExcel process(AddressExcel item) throws Exception {
          System.out.println("Converting " + item);
          log.info("Convert {}", item);
          return item;
      }
  
  }
  </code></pre>
  
  <p>Again, this is never coming into play (no logs generated).  And if it matters, this is how I'm launching my job from a FileUploadController from a @PostMapping("/") to handle the file upload, which first stores the file, then runs the job:</p>
  
  <pre><code>@PostMapping("/")
  public String handleFileUpload(@RequestParam("file") MultipartFile file, RedirectAttributes redirectAttributes) {
  
      storageService.store(file);
  
      try {
          JobParameters jobParameters = new JobParametersBuilder()
                  .addString("file", file.getOriginalFilename().toString()).toJobParameters();
          jobLauncher.run(job, jobParameters);
      } catch (JobExecutionAlreadyRunningException | JobRestartException | JobInstanceAlreadyCompleteException
              | JobParametersInvalidException e) {
          e.printStackTrace();
      }
  
      redirectAttributes.addFlashAttribute("message",
              "You successfully uploaded " + file.getOriginalFilename() + "!");
  
      return "redirect:/";
  }
  </code></pre>
  
  <p>And last by not least</p>
  
  <p><strong>Here is my AddressExcel POJO</strong></p>
  
  <pre><code>import lombok.Data;
  
  @Data
  public class AddressExcel {
  
      private String address1;
      private String address2;
      private String city;
      private String state;
      private String zip;
  
      public AddressExcel() {}
  
  }
  </code></pre>
  
  <p><strong>UPDATE (10/13/2016)</strong>
  From Nghia Do's comments, I also created my own RowMapper instead of using the BeanWrapper to see if that was the issue.  Still the same results.</p>
  
  <pre><code>public class AddressExcelRowMapper implements RowMapper&lt;AddressExcel&gt; {
  
      @Override
      public AddressExcel mapRow(RowSet rs) throws Exception {
          AddressExcel temp = new AddressExcel();
  
          temp.setAddress1(rs.getColumnValue(0));
          temp.setAddress2(rs.getColumnValue(1));
          temp.setCity(rs.getColumnValue(2));
          temp.setState(rs.getColumnValue(3));
          temp.setZip(rs.getColumnValue(4));
  
          return temp;
      }
  
  }
  </code></pre>