Spring Batch - Reference Documentation


Lucas Ward , Dave Syer , Thomas Risberg , Robert Kasanicky , Dan Garrette , Wayne Lund , Michael Minella , Chris Schaefer , Gunnar Hillert


Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically.

Table of Contents

1. Spring Batch Introduction
1.1. Background
1.2. Usage Scenarios
1.3. Spring Batch Architecture
1.4. General Batch Principles and Guidelines
1.5. Batch Processing Strategies
2. What's New in Spring Batch 3.0
2.1. JSR-352 Support
2.2. Promote Spring Batch Integration to Spring Batch
2.3. Upgrade to Support Spring 4 and Java 8
2.4. JobScope Support
2.5. SQLite Support
3. The Domain Language of Batch
3.1. Job
3.1.1. JobInstance
3.1.2. JobParameters
3.1.3. JobExecution
3.2. Step
3.2.1. StepExecution
3.3. ExecutionContext
3.4. JobRepository
3.5. JobLauncher
3.6. Item Reader
3.7. Item Writer
3.8. Item Processor
3.9. Batch Namespace
4. Configuring and Running a Job
4.1. Configuring a Job
4.1.1. Restartability
4.1.2. Intercepting Job Execution
4.1.3. Inheriting from a Parent Job
4.1.4. JobParametersValidator
4.2. Java Config
4.3. Configuring a JobRepository
4.3.1. Transaction Configuration for the JobRepository
4.3.2. Changing the Table Prefix
4.3.3. In-Memory Repository
4.3.4. Non-standard Database Types in a Repository
4.4. Configuring a JobLauncher
4.5. Running a Job
4.5.1. Running Jobs from the Command Line
The CommandLineJobRunner
4.5.2. Running Jobs from within a Web Container
4.6. Advanced Meta-Data Usage
4.6.1. Querying the Repository
4.6.2. JobRegistry
4.6.3. JobOperator
4.6.4. JobParametersIncrementer
4.6.5. Stopping a Job
4.6.6. Aborting a Job
5. Configuring a Step
5.1. Chunk-Oriented Processing
5.1.1. Configuring a Step
5.1.2. Inheriting from a Parent Step
Abstract Step
Merging Lists
5.1.3. The Commit Interval
5.1.4. Configuring a Step for Restart
Setting a StartLimit
Restarting a completed step
Step Restart Configuration Example
5.1.5. Configuring Skip Logic
5.1.6. Configuring Retry Logic
5.1.7. Controlling Rollback
Transactional Readers
5.1.8. Transaction Attributes
5.1.9. Registering ItemStreams with the Step
5.1.10. Intercepting Step Execution
5.2. TaskletStep
5.2.1. TaskletAdapter
5.2.2. Example Tasklet Implementation
5.3. Controlling Step Flow
5.3.1. Sequential Flow
5.3.2. Conditional Flow
Batch Status vs. Exit Status
5.3.3. Configuring for Stop
The 'End' Element
The 'Fail' Element
The 'Stop' Element
5.3.4. Programmatic Flow Decisions
5.3.5. Split Flows
5.3.6. Externalizing Flow Definitions and Dependencies Between Jobs
5.4. Late Binding of Job and Step Attributes
5.4.1. Step Scope
5.4.2. Job Scope
6. ItemReaders and ItemWriters
6.1. ItemReader
6.2. ItemWriter
6.3. ItemProcessor
6.3.1. Chaining ItemProcessors
6.3.2. Filtering Records
6.3.3. Fault Tolerance
6.4. ItemStream
6.5. The Delegate Pattern and Registering with the Step
6.6. Flat Files
6.6.1. The FieldSet
6.6.2. FlatFileItemReader
Simple Delimited File Reading Example
Mapping Fields by Name
Automapping FieldSets to Domain Objects
Fixed Length File Formats
Multiple Record Types within a Single File
Exception Handling in Flat Files
6.6.3. FlatFileItemWriter
Simplified File Writing Example
Delimited File Writing Example
Fixed Width File Writing Example
Handling File Creation
6.7. XML Item Readers and Writers
6.7.1. StaxEventItemReader
6.7.2. StaxEventItemWriter
6.8. Multi-File Input
6.9. Database
6.9.1. Cursor Based ItemReaders
6.9.2. Paging ItemReaders
6.9.3. Database ItemWriters
6.10. Reusing Existing Services
6.11. Validating Input
6.12. Preventing State Persistence
6.13. Creating Custom ItemReaders and ItemWriters
6.13.1. Custom ItemReader Example
Making the ItemReader Restartable
6.13.2. Custom ItemWriter Example
Making the ItemWriter Restartable
7. Scaling and Parallel Processing
7.1. Multi-threaded Step
7.2. Parallel Steps
7.3. Remote Chunking
7.4. Partitioning
7.4.1. PartitionHandler
7.4.2. Partitioner
7.4.3. Binding Input Data to Steps
8. Repeat
8.1. RepeatTemplate
8.1.1. RepeatContext
8.1.2. RepeatStatus
8.2. Completion Policies
8.3. Exception Handling
8.4. Listeners
8.5. Parallel Processing
8.6. Declarative Iteration
9. Retry
9.1. RetryTemplate
9.1.1. RetryContext
9.1.2. RecoveryCallback
9.1.3. Stateless Retry
9.1.4. Stateful Retry
9.2. Retry Policies
9.3. Backoff Policies
9.4. Listeners
9.5. Declarative Retry
10. Unit Testing
10.1. Creating a Unit Test Class
10.2. End-To-End Testing of Batch Jobs
10.3. Testing Individual Steps
10.4. Testing Step-Scoped Components
10.5. Validating Output Files
10.6. Mocking Domain Objects
11. Common Batch Patterns
11.1. Logging Item Processing and Failures
11.2. Stopping a Job Manually for Business Reasons
11.3. Adding a Footer Record
11.3.1. Writing a Summary Footer
11.4. Driving Query Based ItemReaders
11.5. Multi-Line Records
11.6. Executing System Commands
11.7. Handling Step Completion When No Input is Found
11.8. Passing Data to Future Steps
12. JSR-352 Support
12.1. General Notes Spring Batch and JSR-352
12.2. Setup
12.3. Dependency Injection
12.4. Batch Properties
12.4.1. Property Support
12.4.2. @BatchProperty annotation
12.4.3. Property Substitution
12.5. Processing Models
12.5.1. Item based processing
12.5.2. Custom checkpointing
12.6. Running a job
12.7. Contexts
12.8. Step Flow
12.9. Scaling a JSR-352 batch job
12.9.1. Partitioning
12.10. Testing
13. Spring Batch Integration
13.1. Spring Batch Integration Introduction
13.1.1. Namespace Support
13.1.2. Launching Batch Jobs through Messages
Transforming a file into a JobLaunchRequest
The JobExecution Response
Spring Batch Integration Configuration
Example ItemReader Configuration
13.1.3. Providing Feedback with Informational Messages
13.1.4. Asynchronous Processors
13.1.5. Externalizing Batch Process Execution
Remote Chunking
Remote Partitioning
A. List of ItemReaders and ItemWriters
A.1. Item Readers
A.2. Item Writers
B. Meta-Data Schema
B.1. Overview
B.1.1. Example DDL Scripts
B.1.2. Version
B.1.3. Identity
B.8. Archiving
B.9. International and Multi-byte Characters
B.10. Recommendations for Indexing Meta Data Tables
C. Batch Processing and Transactions
C.1. Simple Batching with No Retry
C.2. Simple Stateless Retry
C.3. Typical Repeat-Retry Pattern
C.4. Asynchronous Chunk Processing
C.5. Asynchronous Item Processing
C.6. Interactions Between Batching and Transaction Propagation
C.7. Special Case: Transactions with Orthogonal Resources
C.8. Stateless Retry Cannot Recover