0

我正在寻找一个 Spring Batch 中的实现,它将为平面文件执行 READ -> PROCESS -> WRITE。

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

请建议/指导如何去做。

4

2 回答 2

1

您可以使用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中读取所有文件。.txt/src/main/resources/input

于 2013-05-09T06:09:58.767 回答
0

简单的线索

<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>
于 2014-08-06T12:01:59.047 回答