Java Reference
In-Depth Information
<beans:bean id="dataSource"
<beans:property name="driverClassName"
value="${batch.jdbc.driver}" />
<beans:property name="url" value="${batch.jdbc.url}" />
<beans:property name="username" value="${batch.jdbc.user}" />
<beans:property name="password" value="${batch.jdbc.password}" />
<beans:bean id="transactionManager"
<beans:property name="dataSource" ref="dataSource" />
<beans:bean id="placeholderProperties"
<beans:property name="location" value="" />
<beans:property name="systemPropertiesModeName"
<beans:property name="ignoreUnresolvablePlaceholders"
value="true" />
<beans:property name="order" value="1" />
This launch-context.xml file has a lot going on, so let's take it from the top. In order for the
JMXJobLauncher to be able to start a job, you need a reference to a JobOperator. The first bean in this file
is that configuration. SimpleJobOperator is the only implementation of the JobOperator interface
provided by the Spring Batch framework. You configure it to have access to the JobExplorer,
JobLauncher, JobRepository, and JobRegistry. Given what the JobOperator can do, these dependencies
are all needed.
The JobExplorer is next, to provide read-only access to the JobRepository for many of the objects in
this configuration. After the JobExplorer is a TaskExecutor configuration along with the JobLauncher
used by the JobOperator. The JobLauncher does the work of starting the job and is managed by the
JobOperator for your environment. You configure the JobRepository next; as discussed, this is used by
Spring Batch to maintain the state of your jobs.
The JobRegistry is the next bean configured. Spring Batch provides the ability to register a collection
of jobs in a JobRegistry to be executed on demand. The JobRegistry contains all the jobs that are eligible
to be run in this JVM. In the case of this configuration, you're using Spring Batch's MapJobRegistry ,
which is a Map of jobs available to be run. In order to populate the JobRegistry on startup, you configure
an instance of AutomaticJobRegistrar . This class, as configured in Listing 5-13, reads all the jobs
configured in the /jobs/helloWorldJob.xml file and loads them into the JobRegistry for future use.
The final piece from a Spring Batch perspective in this launch-context.xml file is the configuration
of JMXJobLauncher itself. The rest of the configuration found in this file consists of the datasource,
transaction manager, properties loader, and required elements to expose JMXJobLauncher as an MBean.
With all of the configuration and coding complete, you can now run the main class, Batch , and look
at the beans exposed via JMX with the JConsole application provided by the JDK. To launch the Batch
program, you need to make one last tweak, however. When you create a shell project by using Spring
Batch's simple-cli-archetype , the cli stands for command line interface. The Project Object Model
Search WWH ::

Custom Search