我正在使用spring批处理开发批处理,我有两个步骤,一个更新table1的step1和另一个step2更新了table2 .
我想如果第二步2失败则所有处理都被取消(回滚) . 我该怎么办??
我有以下示例xml配置:
<b:step id="Step1" parent="Tache">
<b:tasklet>
<b:chunk reader="baseReader" processor="baseProcessor"
chunk-completion-policy="completionPolicy" />
</b:tasklet>
</b:step>
<b:step id="Step2" parent="Tache">
<b:tasklet>
<b:chunk reader="baseReaderEcriture"
writer="ecritureWriter" chunk-completion-policy="completionPolicy" />
</b:tasklet>
</b:step>
<b:job id="batch" parent="Batch">
<b:step id="step1" parent="Step1" next="step2"/>
<b:step id="step2" parent="Step2" />
</b:job>
谢谢!
2 回答
您可以't rollback already committed data (after every chunk - based on you completition policy - your data as long as spring-batch metadata are commited), so you can' t自动回滚步骤1中存储的所有数据 .
也许你可以使用这个语法:
要移动到用于删除步骤1中保存的数据的步骤旁边,但您必须知道在
deleteDataSavedByStep1Step
步骤中必须删除哪些数据 .看到这个 . 这可能会给出一个想法 . Spring batch and XA and local transactions
https://blog.codecentric.de/en/2012/03/transactions-in-spring-batch-part-1-the-basics/