如何在Spring Batch中使用db实现多个Reader



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

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

我的问题是,如何实现这个阅读器到当前版本,因为两个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>

withdrawalIbatisKeyGeneratorbean可以注册为StepExecutionListener,其中读取器所需的数据是在StepExecutionListener#beforeStep方法中生成的。

最新更新