Setup

Application Contexts

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 JobRepository, PlatformTransactionManager, etc and a child context that consists of the configuration of the job to be run. The parent context is defined via the baseContext.xml provided by the framework. This context may be overridden via the JSR-352-BASE-CONTEXT system property.

[Note]Note

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.

Launching a JSR-352 based job

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:

JobOperator operator = BatchRuntime.getJobOperator();
				jobOperator.start("myJob", new Properties());

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 BatchRuntime.getJobOperator() is called:

Bean Name Default Configuration Notes
dataSource Apache DBCP BasicDataSource with configured values. By default, HSQLDB is bootstrapped.
transactionManager org.springframework.jdbc.datasource.DataSourceTransactionManager References the dataSource bean defined above.
A Datasource initializer This is configured to execute the scripts configured via the batch.drop.script and batch.schema.script properties. By default, the schema scripts for HSQLDB are executed. This behavior can be disabled via batch.data.source.init property.
jobRepository A JDBC based SimpleJobRepository. This JobRepository uses the previously mentioned data source and transaction manager. The schema's table prefix is configurable (defaults to BATCH_) via the batch.table.prefix property.
jobLauncher org.springframework.batch.core.launch.support.SimpleJobLauncher Used to launch jobs.
batchJobOperator org.springframework.batch.core.launch.support.SimpleJobOperator The JsrJobOperator wraps this to provide most of it's functionality.
jobExplorer org.springframework.batch.core.explore.support.JobExplorerFactoryBean Used to address lookup functionality provided by the JsrJobOperator.
jobParametersConverter org.springframework.batch.core.jsr.JsrJobParametersConverter JSR-352 specific implementation of the JobParametersConverter.
jobRegistry org.springframework.batch.core.configuration.support.MapJobRegistry Used by the SimpleJobOperator.
placeholderProperties org.springframework.beans.factory.config.PropertyPlaceholderConfigure Loads the properties file batch-${ENVIRONMENT:hsql}.properties 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.

[Note]Note

None of the above beans are optional for executing JSR-352 based jobs. All may be overriden to provide customized functionality as needed.