Java Reference
In-Depth Information
form of preprocessing before a component or evaluate the result of a component but also in error
handling, as you see in a bit.
The next section covers the flow of steps. Although all your steps up to this point have been
processed sequentially, that isn't a requirement in Spring Batch. You learn how to perform simple logic
to determine what step to execute next and how to externalize flows for reuse.
Step Flow
A single file line: that is what your jobs have looked like up to this point. You've lined up the steps and
allowed them to execute one after another using the next attribute. However, if that were the only way
you could execute steps, Spring Batch would be very limited. Instead, the authors of the framework
provided a robust collection of options for customizing the flow of your jobs.
To start, let's look at how you can decide what step to execute next or even if you execute a given
step at all. This occurs using Spring Batch's conditional logic.
Conditional Logic
Within a job in Spring Batch, steps are executed in the order you specify using the next attribute of the
step tag. The only requirement is that the first step be configured as the first step in the job. If you want
to execute steps in a different order, it's quite easy: all you need to do is use the next tag. As Listing 4-40
shows, you can use the next tag to direct a job to go from step1 to step2a if things go ok or to step2b if
step1 returns an ExitStatus of FAILED .
Listing 4-40. If / Else Logic in Step Execution
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns=""
<beans:import resource="../launch-context.xml"/>
<beans:bean id="passTasklet"
<beans:property name="success" value="true"/>
<beans:bean id="successTasklet"
<beans:property name="message" value="The step succeeded!"/>
<beans:bean id="failTasklet"
<beans:property name="message" value="The step failed!"/>
Search WWH ::

Custom Search