The application layer spends most of its time interacting with the next layer, the core. The core layer
contains all the pieces that define the batch domain. Elements of the core component include the Job
and Step interfaces as well as the interfaces used to execute a Job: JobLauncher and JobParameters.
Below all this is the infrastructure layer . In order to do any processing, you need to read and write
from files, databases, and so on. You must be able to handle what to do when a job is retried after a
failure. These pieces are considered common infrastructure and live in the infrastructure component of
Note A common misconception is that Spring Batch is or has a scheduler. It doesn't. There is no way within the
framework to schedule a job to run at a given time or based on a given event. There are a number of ways to
launch a job, from a simple cron script to Quartz or even an enterprise scheduler like UC4, but none within the
framework itself. Chapter 6 covers launching a job.
Let's walk through some features of Spring Batch.
Defining Jobs with Spring
Batch processes have a number of different domain-specific concepts. A job is a process that consists of
a number of steps. There maybe input and output related to each step. When a step fails, it may or may
not be repeatable. The flow of a job may be conditional (for example, execute the bonus calculation step
only if the revenue calculation step returns revenue over $1,000,000). Spring Batch provides classes,
interfaces, and XML schemas that define these concepts using POJOs and XML to divide concerns
appropriately and wire them together in a way familiar to those who have used Spring. Listing 1-1, for
example, shows a basic Spring Batch job configured in XML. The result is a framework for batch
processing that you can pick up very quickly with only a basic understanding of Spring as a prerequisite.
Listing 1-1. Sample Spring Batch Job Definition
It's one thing to be able to write a Java program that processes some data once and never runs again. But
mission-critical processes require a more robust approach. The ability to keep the state of a job for
reexecution, maintaining data integrity when a job fails through transaction management and saving
performance metrics of past job executions for trending, are features that you expect in an enterprise
batch system. These features are included in Spring Batch, and most of them are turned on by default;
they require only minimal tweaking for performance and requirements as you develop your process.