Spring batch spring批处理中的通用项读取器和项编写器

Spring batch spring批处理中的通用项读取器和项编写器,spring-batch,Spring Batch,如何编写通用项目读取器和项目编写器,以便在作业的所有步骤中重复使用相同的读取器和编写器。请帮助 提前感谢。Spring Batch作为ItemReader、ItemProcessor和ItemWriter适配器“开箱即用”,可以帮助实现许多通用功能。本质上,ItemReaderAdapter允许您调用现有对象和方法,而无需编写自己的读取器 下面是一个配置示例 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://

如何编写通用项目读取器和项目编写器,以便在作业的所有步骤中重复使用相同的读取器和编写器。请帮助


提前感谢。

Spring Batch作为
ItemReader
ItemProcessor
ItemWriter
适配器“开箱即用”,可以帮助实现许多通用功能。本质上,
ItemReaderAdapter
允许您调用现有对象和方法,而无需编写自己的读取器

下面是一个配置示例

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:batch="http://www.springframework.org/schema/batch"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd">


    <batch:job id="sampleJob">
        <batch:step id="sampleJob.step1">
            <batch:tasklet>
                <batch:chunk reader="readerAdapter" writer="..." commit-interval="10"/>
            </batch:tasklet>
        </batch:step>
    </batch:job>

    <bean id="readerAdapter" class="org.springframework.batch.item.adapter.ItemReaderAdapter" scope="step">
        <property name="targetObject" ref="myService"/>
        <property name="targetMethod" value="get"/>
        <property name="arguments" value="#{jobParameters['parameterName']}"/>
    </bean>

    <bean id="myService"/>

</beans>


块中的每个“阶段”都有适配器。查看每个适配器上的javadoc,如果您的服务返回正确类型的对象以参与区块,它们将有助于更好地了解情况。

您能详细说明您的问题吗?你想达到什么目标?是否所有步骤都从同一源读取和写入?是,所有步骤都从单个Xml文件读取并写入数据库表。