After you've run the job, notice that in traditional Spring style, there is quite a bit of output for a simple
“Hello, World!” But if you look closely (around line 33 of the output), there it is:
2010-12-01 23:15:42,442 DEBUG
[org.springframework.batch.core.scope.context.StepContextRepeatCallback] - <Chunk execution
starting: queue size=0>
2010-12-01 23:15:42,443 DEBUG
[org.springframework.batch.core.step.tasklet.TaskletStep] - <Applying contribution:
[StepContribution: read=0, written=0, fi ltered=0, readSkips=0, writeSkips=0, processSkips=0,
Congratulations! You just ran your first Spring Batch job. So, what actually happened? As discussed
earlier in the chapter, when Spring Batch runs a job, the job runner (in this case, the
CommandLineJobRunner) loads the application context and configuration of the job to be run (as
specified by the first two parameters passed in). From there, the job runner passes the JobInstance to a
JobLauncher that executes the job. In this case, the job's single step is executed, and the JobRepository is
Exploring the JobRepository
Wait. JobRepository? That wasn't specified in your XML. Where did all that information go? It went into
the job repository, as it should. The problem is that Spring Batch is configured to use HSQLDB by
default, so all that metadata, although stored in memory during the execution of the job, is now gone.
Let's fix that by switching to MySQL instead so you can do a better job managing the metadata and look
at what happens when you run your job. In this section, you look at how to configure your JobRepository
to use MySQL, and you explore what Spring Batch logs to the database with a run of HelloWorldJob.
Job Repository Configuration
To change where Spring Batch stores the data, you need to do three things: update the batch.properties
file, update your pom, and create the batch schema in your database. 3 Let's start by modifying the
batch.properties file found in your project's /src/main/resources directory. The properties should be
pretty straightforward. Listing 2-7 shows what I have in mine.
Listing 2-7. batch.properties File
3 I'm going to assume you already have MySQL installed. If you don't, go to www.mysql.com to download it
and get installation instructions.