How to read all files in a folder with spring-batch and MultiResourceItemReader?

后端 未结 4 458
眼角桃花
眼角桃花 2020-12-29 10:37

I want to configure spring-batch to read all csv files inside a specific folder sequentially.

The following does not work because the deleg

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-29 10:40

    Use PathMatchingResourcePatternResolver like this.

    @Bean
    public ItemReader reader() {
        Resource[] resources = null;
        ResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();   
        try {
            resources = patternResolver.getResources("/myfolder/*.csv");
        } catch (IOException e) {
            e.printStackTrace();
        }
        MultiResourceItemReader reader = new MultiResourceItemReader<>();
        reader.setResources(resources);
        reader.setDelegate(new FlatFileItemReader<>(..));
        return reader;
    

    }

提交回复
热议问题