org.springframework.batch.item.file.MultiResourceItemReader Java Examples

The following examples show how to use org.springframework.batch.item.file.MultiResourceItemReader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CapitalizeNamesJobConfig.java    From spring-batch with MIT License 6 votes vote down vote up
@Bean
public MultiResourceItemReader<Person> multiItemReader() {
  ResourcePatternResolver patternResolver =
      new PathMatchingResourcePatternResolver();
  Resource[] resources = null;
  try {
    resources = patternResolver
        .getResources("file:target/test-inputs/*.csv");
  } catch (IOException e) {
    LOGGER.error("error reading files", e);
  }

  return new MultiResourceItemReaderBuilder<Person>()
      .name("multiPersonItemReader").delegate(itemReader())
      .resources(resources).setStrict(true).build();
}
 
Example #2
Source File: MultiFileIteamReaderDemo.java    From SpringAll with MIT License 5 votes vote down vote up
private ItemReader<TestData> multiFileItemReader() {
    MultiResourceItemReader<TestData> reader = new MultiResourceItemReader<>();
    reader.setDelegate(fileItemReader()); // 设置文件读取代理,方法可以使用前面文件读取中的例子

    Resource[] resources = new Resource[]{
            new ClassPathResource("file1"),
            new ClassPathResource("file2")
    };

    reader.setResources(resources); // 设置多文件源
    return reader;
}