Files
spring-batch/build/reference-epub-work/ch12s02.xhtml
Michael Minella 75ab909314 update
2017-03-23 10:18:33 -05:00

90 lines
9.4 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg"><head><title>Setup</title><link rel="stylesheet" type="text/css" href="docbook-epub.css"/><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"/><link rel="prev" href="ch12.xhtml" title="Chapter 12. JSR-352 Support"/><link rel="next" href="ch12s03.xhtml" title="Dependency Injection"/></head><body><header/><section class="section" title="Setup" epub:type="subchapter" id="jsrSetup"><div class="titlepage"><div><div><h2 class="title" style="clear: both">Setup</h2></div></div></div><section class="section" title="Application Contexts" epub:type="division" id="jsrSetupContexts"><div class="titlepage"><div><div><h3 class="title">Application Contexts</h3></div></div></div><p>All JSR-352 based jobs within Spring Batch consist of two application contexts. A parent context, that
contains beans related to the infrastructure of Spring Batch such as the <code class="classname">JobRepository</code>,
<code class="classname">PlatformTransactionManager</code>, etc and a child context that consists of the configuration
of the job to be run. The parent context is defined via the <code class="classname">baseContext.xml</code> provided
by the framework. This context may be overridden via the <code class="classname">JSR-352-BASE-CONTEXT</code> system
property.</p><div class="note" title="Note" epub:type="notice"><table style="border: 0; "><tr><td style="text-align: center; vertical-align: top; width: 25; " rowspan="2"><img alt="[Note]" src="images/note.png"/></td><th style="text-align: left; ">Note</th></tr><tr><td style="text-align: left; vertical-align: top; "><p>The base context is not processed by the JSR-352 processors for things like property injection so
no components requiring that additional processing should be configured there.
</p></td></tr></table></div></section><section class="section" title="Launching a JSR-352 based job" epub:type="division" id="jsrSetupLaunching"><div class="titlepage"><div><div><h3 class="title">Launching a JSR-352 based job</h3></div></div></div><p>JSR-352 requires a very simple path to executing a batch job. The following code is all that is needed to
execute your first batch job:
</p><pre class="programlisting">JobOperator operator = BatchRuntime.getJobOperator();
jobOperator.start("myJob", new Properties());</pre><p>While that is convenient for developers, the devil is in the details. Spring Batch bootstraps a bit of
infrastructure behind the scenes that a developer may want to override. The following is bootstrapped the
first time <code class="code">BatchRuntime.getJobOperator()</code> is called:
</p><div class="informaltable"><table style="border-collapse: collapse; border-top: 0.5pt solid ; border-bottom: 0.5pt solid ; border-left: 0.5pt solid ; border-right: 0.5pt solid ; "><colgroup><col style="text-align: left; "/><col style="text-align: left; "/><col style="text-align: left; "/></colgroup><tbody><tr><td style="text-align: left; border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">
<span class="bold"><strong>Bean Name</strong></span>
</td><td style="text-align: left; border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">
<span class="bold"><strong>Default Configuration</strong></span>
</td><td style="text-align: left; border-bottom: 0.5pt solid ; ">
<span class="bold"><strong>Notes</strong></span>
</td></tr><tr><td style="text-align: left; border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">
dataSource
</td><td style="text-align: left; border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">
Apache DBCP BasicDataSource with configured values.
</td><td style="text-align: left; border-bottom: 0.5pt solid ; ">
By default, HSQLDB is bootstrapped.
</td></tr><tr><td style="text-align: left; border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">
<code class="code">transactionManager</code>
</td><td style="text-align: left; border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">
<code class="code">org.springframework.jdbc.datasource.DataSourceTransactionManager</code>
</td><td style="text-align: left; border-bottom: 0.5pt solid ; ">
References the dataSource bean defined above.
</td></tr><tr><td style="text-align: left; border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">
A Datasource initializer
</td><td style="text-align: left; border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">
</td><td style="text-align: left; border-bottom: 0.5pt solid ; ">
This is configured to execute the scripts configured via the
<code class="code">batch.drop.script</code> and <code class="code">batch.schema.script</code> properties. By
default, the schema scripts for HSQLDB are executed. This behavior can be disabled via
<code class="code">batch.data.source.init</code> property.
</td></tr><tr><td style="text-align: left; border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">
jobRepository
</td><td style="text-align: left; border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">
A JDBC based <code class="code">SimpleJobRepository</code>.
</td><td style="text-align: left; border-bottom: 0.5pt solid ; ">
This <code class="code">JobRepository</code> uses the previously mentioned data source and transaction
manager. The schema's table prefix is configurable (defaults to BATCH_) via the
<code class="code">batch.table.prefix</code> property.
</td></tr><tr><td style="text-align: left; border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">
jobLauncher
</td><td style="text-align: left; border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">
<code class="code">org.springframework.batch.core.launch.support.SimpleJobLauncher</code>
</td><td style="text-align: left; border-bottom: 0.5pt solid ; ">
Used to launch jobs.
</td></tr><tr><td style="text-align: left; border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">
batchJobOperator
</td><td style="text-align: left; border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">
<code class="code">org.springframework.batch.core.launch.support.SimpleJobOperator</code>
</td><td style="text-align: left; border-bottom: 0.5pt solid ; ">
The <code class="code">JsrJobOperator</code> wraps this to provide most of it's functionality.
</td></tr><tr><td style="text-align: left; border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">
jobExplorer
</td><td style="text-align: left; border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">
<code class="code">org.springframework.batch.core.explore.support.JobExplorerFactoryBean</code>
</td><td style="text-align: left; border-bottom: 0.5pt solid ; ">
Used to address lookup functionality provided by the <code class="code">JsrJobOperator</code>.
</td></tr><tr><td style="text-align: left; border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">
jobParametersConverter
</td><td style="text-align: left; border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">
<code class="code">org.springframework.batch.core.jsr.JsrJobParametersConverter</code>
</td><td style="text-align: left; border-bottom: 0.5pt solid ; ">
JSR-352 specific implementation of the <code class="code">JobParametersConverter</code>.
</td></tr><tr><td style="text-align: left; border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">
jobRegistry
</td><td style="text-align: left; border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">
<code class="code">org.springframework.batch.core.configuration.support.MapJobRegistry</code>
</td><td style="text-align: left; border-bottom: 0.5pt solid ; ">
Used by the <code class="code">SimpleJobOperator</code>.
</td></tr><tr><td style="text-align: left; border-right: 0.5pt solid ; ">
placeholderProperties
</td><td style="text-align: left; border-right: 0.5pt solid ; ">
<code class="code">org.springframework.beans.factory.config.PropertyPlaceholderConfigure</code>
</td><td style="text-align: left; ">
Loads the properties file <code class="code">batch-${ENVIRONMENT:hsql}.properties</code> to configure
the properties mentioned above. ENVIRONMENT is a System property (defaults to hsql)
that can be used to specify any of the supported databases Spring Batch currently
supports.
</td></tr></tbody></table></div><p>
</p><div class="note" title="Note" epub:type="notice"><table style="border: 0; "><tr><td style="text-align: center; vertical-align: top; width: 25; " rowspan="2"><img alt="[Note]" src="images/note.png"/></td><th style="text-align: left; ">Note</th></tr><tr><td style="text-align: left; vertical-align: top; "><p>None of the above beans are optional for executing JSR-352 based jobs. All may be overriden to
provide customized functionality as needed.
</p></td></tr></table></div></section></section><footer/></body></html>