Java Reference
In-Depth Information
Let's look at an example that executes one of two step s based on the success of a preceding step :
<step id="step1" >
<next on="COMPLETED" to="step2" > <!-- ... --></step>
<next on="FAILED" to="failureStep" > <!-- ... --></step>
</step>
It's also possible to provide a wildcard. This is useful if you want to ensure a certain behavior for any
number of BatchStatus , perhaps in tandem with a more specific next element that matches only one
BatchStatus .
<step id="step1" >
<next on="COMPLETED" to="step2" > <!-- ... --></step>
<next on="*" to="failureStep" > <!-- ... --></step>
</step>
In this example, you are instructing it to perform some step based on any unaccounted-for
ExitStatus . Another option is to just stop processing altogether with a BatchStatus of FAILED . You can do
this using the fail element. A less aggressive rewrite of the preceding example might be the following:
<step id="step1" >
<next on="COMPLETED" to="step2" />
<fail on="FAILED" />
<!-- ... -->
</step>
In all these examples, you're reacting to the standard BatchStatus es that the Spring Batch
framework provides. But it's also possible to raise your own ExitStatus . If, for example, you wanted
the whole job to fail with a custom ExitStatus of "MAN DOWN" , you might do something like this:
<step id="step1" next="step2"><!-- ... --></step>
<step id="step2" parent="s2">
<fail on="FAILED" exit-code="MAN DOWN "/>
<next on="*" to="step3"/>
</step>
<step id="step3"><!-- ... --></step>
Finally, if all you want to do is end processing with a BatchStatus of COMPLETED , you can use the end
element. This is an explicit way of ending a flow as if it had run out of steps and incurred no errors.
<next on="COMPLETED" to="step2" />
<step id="step2" >
<end on="COMPLETED"/>
<next on="FAILED" to="errorStep"/>
<!-- ... -->
</step>
Conditional Steps with Decisions
If you want to vary the execution flow based on some logic more complex than a job 's ExitStatus es,
you may give Spring Batch a helping hand by using a decision element and providing it with an
implementation of a JobExecutionDecider .
Search WWH ::




Custom Search