Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
spring批处理读取进程写入多个文件_Spring - Fatal编程技术网

spring批处理读取进程写入多个文件

spring批处理读取进程写入多个文件,spring,Spring,我正在寻找SpringBatch中的一个实现,它将对平面文件执行读取->处理->写入 我们将从输入文件夹中读取10个文件,然后在输出文件夹中写入10个文件。对于每个输入文件,将对数据进行一些处理/转换,并相应地生成一个输出(转换)文件 请建议/指导如何操作。您可以使用MultiResourceItemReader 请参阅下面的示例代码 <bean id="multiResourceItemReader" class="org.springframework.batch.item.file.

我正在寻找SpringBatch中的一个实现,它将对平面文件执行读取->处理->写入

我们将从输入文件夹中读取10个文件,然后在输出文件夹中写入10个文件。对于每个输入文件,将对数据进行一些处理/转换,并相应地生成一个输出(转换)文件


请建议/指导如何操作。

您可以使用
MultiResourceItemReader

请参阅下面的示例代码

<bean id="multiResourceItemReader" class="org.springframework.batch.item.file.MultiResourceItemReader">
        <property name="resources"
 value="file:./src/main/resources/input/*.txt" />       <property
 name="delegate">           <bean
 class="org.springframework.batch.item.file.FlatFileItemReader">
                <property name="lineMapper">
                    <bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
                        <property name="lineTokenizer">
                            <bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
                                <property name="names" value="firstname,lastname,birth" />
                            </bean>
                        </property>
                        <property name="fieldSetMapper">
                            <bean class="com.zenika.workshop.springbatch.ContactFieldSetMapper" />
                        </property>
                    </bean>
                </property>             </bean>         </property>     </bean>

这里的
MultiResourceItemReader
正在读取
/src/main/resources/input
文件夹中的所有
.txt
文件。

简单提示

<bean   class="CustomReader1"   id="cr1">
    <property   name="folderLocation" value="/path/to/sourcefiles/parent/directory/"/>
</bean>
<bean   class="CustomReader2"   id="cr2">
    <property   name="filesLocations">
        <list>
            <value>/path/to/sourcefiles/parent/directory/file1.txt</value>
            <value>/path/to/sourcefiles/parent/directory/file2.txt</value>
            <value>/path/to/sourcefiles/parent/directory1/file1.txt</value>
            <value>/path/to/sourcefiles/parent2/directory/file1.txt</value>
        </list>
    </property>
</bean>
<bean   class="MainItemReader"  id="mainItemReader">
    <property   name="itemReaders">
        <list>
            <bean   ref="cr1"/>
            <bean   ref="cr2"/>
        </list>
    </property>
</bean>

/path/to/sourcefiles/parent/directory/file1.txt
/path/to/sourcefiles/parent/directory/file2.txt
/path/to/sourcefiles/parent/directory1/file1.txt
/path/to/sourcefiles/parent2/directory/file1.txt