Java Reference
In-Depth Information
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-2.1.xsd" >
<beans:import resource="../launch-context.xml"/>
<beans:bean id="helloWorld"
class="com.apress.springbatch.chapter2.HelloWorld"/>
<step id="helloWorldStep">
<tasklet ref="helloWorld"/>
</step>
<job id="helloWorldJob">
<step id="step1" parent="helloWorldStep"/>
</job>
</beans:beans>
If that looks kind of familiar, it should. It's the high-level breakdown discussed previously, only in XML
form.
Note Although most of Spring has added annotation equivalents to the XML con fi guration options, Spring Batch
doesn't. As part of the 2.0 release, Spring did add a namespace to assist with managing the XML.
If you walk through this, there are four main pieces: the import of launch-context.xml, the bean
declaration, the step definition, and the job definition. Launch-context.xml is a file that is included in
your shell project that contains a number of infrastructure pieces configured for your jobs. Things like
the datasource, the JobLauncher, and other elements universal to all the jobs in the project are found
here. Chapter 3 covers this file in more detail. For now, the default settings work.
The bean declaration should look like any other Spring bean, for a good reason: it's just like any
other Spring bean. The HelloWorld bean is a tasklet that does the work in this job. A tasklet is a special
type of step that is used to perform a function without a reader or writer. Typically, a tasklet is used for a
single function, say performing some initialization, calling a stored procedure, or sending an e-mail to
alert you that the job has finished. Chapter 4 goes into semantic specifics about tasklets along with the
other step types.
The next piece is the step. Jobs are made up of one or more steps, as noted earlier. In the HelloWorld
job, you start with a single step that executes your tasklet. Spring Batch provides an easy way to
configure a step using the batch XSD. You create a tasklet using the tasklet tag and reference the tasklet
you defined previously. You then wrap that in a step tag with just an id. This defines a reusable step that
you can reference in your job as many times as you need.
Finally, you define your job. The job is really nothing more than an ordered list of steps to be
executed. In this case, you have only one step. If you're wondering if the step tag in the job definition is
Search WWH ::




Custom Search