如何使用spring-batch和MultiResourceItemReader读取文件夹中的所有文件? [英] How to read all files in a folder with spring-batch and MultiResourceItemReader?

查看:169
本文介绍了如何使用spring-batch和MultiResourceItemReader读取文件夹中的所有文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想配置spring-batch以便顺序读取特定文件夹中的所有csv文件.

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

以下内容不起作用,因为该委托将尝试打开一个名为*.csv的文件,该文件当然是无效的.我必须在这里更改什么?

The following does not work because the delegate will try to open a file named *.csv, which of course is invalid. What do I have to change here?

    @Bean
    public ItemReader<String> reader() {
        MultiResourceItemReader<String> reader = new MultiResourceItemReader<>();
        reader.setResources(new Resource[] {new FileSystemResource("/myfolder/*.csv")});
        reader.setDelegate(new FlatFileItemReader<>(..));
        return reader;
}

等效的xml配置将编写如下,如何将其重写为仅Java的配置?

The equivalent xml configuration would be written as follows, how could I rewrite it to java only config?

<bean id="reader" class="org.springframework.batch.item.file.MultiResourceItemReader">
        <property name="resources" value="/mypfolder/*.csv"/>
        <property name="delegate" ref="flatFileItemReader"/>
</bean>

推荐答案

我认为您应该使用

I think you should use a PathMatchingResourcePatternResolver.

这篇关于如何使用spring-batch和MultiResourceItemReader读取文件夹中的所有文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆