Today we are pleased to announce the first milestone release towards Spring Batch 3.0 (download). With this release we take our first steps towards implementing the JSR-352 Java Batch specification. Spring Batch is a lightweight, comprehensive framework for the development of robust batch applications.
JSR-352 is billed as the standardization of batch processing for the java platform. As part of that standardization, this JSR has included three main pieces:
- A XML based DSL for configuring jobs
- An API for creating job related components (readers/writers/etc)
- An API and description of behavior for a supporting classes and concepts
Spring has invested a large amount of time and resources in our contribution to this spec. Our collaboration with the other industry experts via the JCP, JSR-352 validates that the batch patterns that Spring Batch has implemented and battle tested over the past five years in countless production environments is the best approach for building mission critical batch applications.
Features in Milestone 1
This release is the first step towards Spring Batch being compliant with the JSR. Out of the 155 SE tests in the JSR-352 TCK, this release passes 70. The specific features implemented within this release are:
- Basic Job configuration via XML
- batch.xml support
The JSR defines a
JobOperator interface that is a combination of Spring Batch's
JobExplorer interfaces. For the spec, this interface serves as the entry point for a batch application to both interact with the job itself (start/stop/restart/etc) as well as the job repository (providing the ability to query for previously run JobExecutions for example). Because of this, the
JobOperator needs to provide a level of services out of the box. The
JsrJobOperator (the Spring implementation of
javax.batch.operations.JobOperator) bootstraps a Spring context similar to that of
@EnableBatchProcessing. Out of the box, it includes a
JobRegistry, and a
PlaceholderPropertiesConfigurer. All of these can be overridden at runtime by overriding the default beans via the context provided when starting or restarting a job. By default, the
JobRepository utilizes HSQLDB in an in-memory configuration.
Per the JSR, to launch a job is actually very easy:
JobOperator jobOperator = BatchRuntime.getJobOperator();
JobExecution jobExecution = jobOperator.start("jsrJob", new Properties());
The above two lines will bootstrap the previously defined base context (this occurs only once), then loads the batch.xml file from /META-INF (if it exists) and the context as defined at jsrJob.xml in /META-INF/batch-jobs. jsrJob.xml can be one of two configurations. It can be a standard Spring context configuration that defines any batch artifacts as Spring Beans and the job via the JSR-352 DSL, or it can be just the job definition as defined by the JSR. Per JSR-352, only one job can be defined within the jsrJob.xml context. The rest of the
JsrJobOperator's functionality is virtually a direct wrapping of the existing
JobExplorer's functionality (hence their inclusion in the base application context).
Basic Job configuration via XML
JSR-352 defines an XML based DSL that any Spring Batch user will immediately find familiar. Consisting of jobs, steps, readers and writers, most of the concepts that are found in the Spring Batch namespace are accounted for within JSR-352. As part of this release, developers will be able to configure basic jobs using the JSR defined DSL. Basic jobs include the following:
<skippable-exception-classes> and related children
<retryable-exception-classes> and related children
With the JSR, a batch job that looks like this via the Spring Batch DSL:
<job id="data" xmlns="http://www.springframework.org/schema/batch">
<step id="import" next="report">