我第一次使用Spring Batch。我嘗試了一些例子並通讀文檔。但我仍然有疑問:如何在Spring批處理中使用塊處理?
我可以跳過面向塊處理中的一個階段嗎?例如:我從數據庫獲取數據,處理數據並確定需要更多數據,我可以跳過寫入階段並執行下一步的讀取階段嗎?我應該使用Tasklet嗎?
如何實現條件流?
非常感謝你, 弗洛裏安
我第一次使用Spring Batch。我嘗試了一些例子並通讀文檔。但我仍然有疑問:如何在Spring批處理中使用塊處理?
我可以跳過面向塊處理中的一個階段嗎?例如:我從數據庫獲取數據,處理數據並確定需要更多數據,我可以跳過寫入階段並執行下一步的讀取階段嗎?我應該使用Tasklet嗎?
如何實現條件流?
非常感謝你, 弗洛裏安
跳過塊簡單地拋出已被宣佈爲「可跳過的異常」的異常。
<step id="step1">
<tasklet>
<chunk reader="reader" writer="writer"
commit-interval="10" skip-limit="10">
<skippable-exception-classes>
<include class="com.myapp.batch.MyException"/>
</skippable-exception-classes>
</chunk>
</tasklet>
</step>
條件流可以很容易地實現決定分步執行的ExitStatus
:
<job id="job">
<step id="step1" parent="s1">
<next on="*" to="stepB" />
<next on="FAILED" to="stepC" />
</step>
<step id="stepB" parent="s2" next="stepC" />
<step id="stepC" parent="s3" />
</job>
閱讀文檔獲得關於這些更深層次的知識,你可以如下做到這一點話題:http://docs.spring.io/spring-batch/reference/html/configureStep.html
謝謝!我還剩下一個問題:如何在步驟之間傳遞參數? –
@FlorianMozart http://docs.spring.io/spring-batch/reference/html-single/index.html#passingDataToFutureSteps – achingfingers
我很困惑。爲什麼我會得到一個投票? –