如何在 Spring 批处理中使用 db 实现多个 Reader

How to implement multiple Reader using db in Spring Batch

此代码是 Spring 批处理版本 1 的一个版本。我在将此代码迁移到版本 4 时遇到问题,因为 org.springframework.batch.item.database.IbatisDrivingQueryItemReader class 在当前版本中不再可用。

下面代码的过程是,withdrawalIbatisKeyGenerator bean 应该首先执行,并且从那个 bean 的输出中,它将在 ibatisWithdrawalReader bean 中使用。

我的问题是,如何将这个 reader 实现到当前版本,因为这两个 bean 相互依赖。

<bean id="ibatisWithdrawalReader"
        class="org.springframework.batch.item.database.IbatisDrivingQueryItemReader">
        <property name="detailsQueryId"
            value="withdrawalTransactionDao.getWithdrawalTransaction" />
        <property name="sqlMapClient" ref="sqlMap" />
        <property name="keyCollector"
            ref="withdrawalIbatisKeyGenerator" />
    </bean>



<bean id="withdrawalIbatisKeyGenerator"
        class="ph.pnblife.julia.batch.BatchKeyCollector">
        <property name="drivingQuery"
            value="withdrawalTransactionDao.getWithdrawalTransactionKey" />
        <property name="restartQueryId"
            value="withdrawalTransactionDao.restartWithdrawalTransaction" />
        <property name="sqlMapClient" ref="sqlMap" />
        <property name="parameters">
            <list>
                <value>%%pricing_date_ibatis:date:pricing_date</value>
                <value>%%policy_number:string:pol_no</value>
                <value>%%version_no:string:version_no</value>
                <value>%%start_date:date:start_dt</value>
                <value>%%endt_type:string:endt_code</value>
            </list>
        </property>
        <property name="isKeyAMap">
            <value type="java.lang.Boolean">true</value>
        </property>
    </bean>

withdrawalIbatisKeyGenerator bean 可以注册为 StepExecutionListener,其中 reader 所需的数据是在 StepExecutionListener#beforeStep 方法中生成的。