title: accessing resources in next steps spring batch
body: <p>Hello I have the follow Tasklet in my spring batch application:</p>
  
  <pre><code>public class FileMovingTasklet implements Tasklet, InitializingBean {
  
  
      @Value("${positionFile.source-path}")
      private String sourcePath;
  
      @Value("${positionFile.local-path}")
      private String localDirectory;
  
      @Value("${positionFile.patternName}")
      private String fileNamePattern;
  
      @Value("${positionFile.suffix}")
      private String suffix;
  
      @Override
      public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
  
          //***code***
  
              List&lt;PathResource&gt; resources = FileManager.getInputFileList(sourcePath, fileNamePattern, suffix, fileDate);
  
              if (!CollectionUtils.isEmpty(resources)) {
                  copyFiles(resources, localDirectory);
                  log.info("Copied files to local directory...");
  
              }
  
          } catch (IOException e) {
              log.error("Position File not found with sourcePatch={}, fileName={}, suffix={}, filedate={}", sourcePath, fileNamePattern, suffix, fileDate);
              throw new TaskletException("Could not move file from source to local " + e);
          }
  
          return RepeatStatus.FINISHED;
      }
  
      private void copyFiles(List&lt;PathResource&gt; resources, String localDirectory) {
  
          for (Resource resource : resources) {
  
              File source;
              File target;
  
              try {
                  source = resource.getFile();
                  target = new File(localDirectory + File.separator + source.getName());
  
                  try {
                      FileCopyUtils.copy(source, target);
                  } catch (IOException e) {
  
                  }
              } catch (IOException e) {
              }
          }
  
      }
  
  }
  </code></pre>
  
  <p>I am moving some files from source to my local destination. The local destination is where I want to to read in files and process and write in my subsequent steps.</p>
  
  <p>I have configured my <code>Job</code> as follows:</p>
  
  <pre><code>@Configuration
  public class BatchConfiguration {
  
      @Autowired
      private JobBuilderFactory jobBuilderFactory;
  
      @Autowired
      private StepBuilderFactory stepBuilderFactory;
  
      @Autowired
      private FileMovingTasklet fileMovingTasklet;
  
      @Value("${positionFile.local-path}")
      private Resource[] resources;
  
      @Autowired
      private PriceDao scpDao;
  
      @Autowired
      public PositionRowReader positionRowReader;
  
  
      @Bean
      public MultiResourceItemReader&lt;Pos&gt; multiResourceItemReader() {
          MultiResourceItemReader&lt;Pos&gt; resourceItemReader = new MultiResourceItemReader&lt;&gt;();
          resourceItemReader.setResources(resources);
          resourceItemReader.setDelegate(posRowReader());
          return resourceItemReader;
      }
  
      @Bean
      public FlatFileItemReader&lt;Pos&gt; posRowReader() {
          return positionRowReader.getReader();
      }
  
  
      @Bean
      public ItemProcessor&lt;Pos, Price&gt; posRowProcessor() {
          return new PosRowItemProcessor();
      }
  
  
      @Bean
      public JobExecutionListener listener() {
          return new JobCompletionNotificationListener(scpDao);
      }
  
  
      @Bean
      public Job import() {
          return jobBuilderFactory.get("import")
                  .incrementer(new RunIdIncrementer())
                  .listener(listener())
                  .start(getPositionFileStep())
                  .next(step1())
                  .build();
      }
  
  
      @Bean
      public Step getPositionFileStep() {
          return stepBuilderFactory.get("getPositionFileStep")
                  .tasklet(fileMovingTasklet)
                  .build();
      }
  
      @Bean
      public Step step1() {
          return stepBuilderFactory.get("step1")
                  .&lt;Pos, Price&gt;chunk(50)
                  .reader(multiResourceItemReader())
                  .processor(posRowProcessor())
                  .writer(new PriceWriter(scpDao))
                  .build();
      }
  
  
  
  }
  </code></pre>
  
  <p>I get failed to initialize the reader when executing <strong>step1</strong>:</p>
  
  <pre><code>org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
  </code></pre>
  
  <p>my local-path property is as follows:</p>
  
  <pre><code>positionFile.local-path=C:\\Dev\\workspace\\batch\\src\\main\\resources\\localPath
  
  positionFile.patterName=PositionFile*
  </code></pre>
  
  <p>my question is how can I access the resources (files) which can be multiple files in step1 after files have been copied over from source folder. </p>
  
  <p>My resources size is 0 even though files are there:</p>
  
  <pre><code>   @Value("${positionFile.local-path}")
      private String filePath;
  
      @Value("${positionFile.patternName}")
      private String filePattern;
  
  
      @Bean
      @StepScope
      public MultiResourceItemReader&lt;PosRow&gt; multiResourceItemReader() {
          MultiResourceItemReader&lt;PosRow&gt; resourceItemReader = new MultiResourceItemReader&lt;&gt;();
          Resource[] resources = new Resource[0];
          try {
              ClassLoader cl = this.getClass().getClassLoader();
              ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cl);
              resources = resolver.getResources("file:" + filePath + File.separator + filePattern + "*");
          } catch (IOException e) {
              log.error("Problem with getting resource files");
          }
          resourceItemReader.setResources(resources);
          resourceItemReader.setDelegate(posRowReader());
          return resourceItemReader;
      }
  </code></pre>