Spring Batch - Reference Documentation
Table of Contents
1. Spring Batch Introduction
Background
Usage Scenarios
Spring Batch Architecture
General Batch Principles and Guidelines
Batch Processing Strategies
2. What's New in Spring Batch 4.0
Java 8 Requirement
Dependencies re-baseline
Provide builders for the ItemReaders and ItemWriters
3. The Domain Language of Batch
Job
JobInstance
JobParameters
JobExecution
Step
StepExecution
ExecutionContext
JobRepository
JobLauncher
Item Reader
Item Writer
Item Processor
Batch Namespace
4. Configuring and Running a Job
Configuring a Job
Restartability
Intercepting Job Execution
Inheriting from a Parent Job
JobParametersValidator
Java Config
Configuring a JobRepository
Transaction Configuration for the JobRepository
Changing the Table Prefix
In-Memory Repository
Non-standard Database Types in a Repository
Configuring a JobLauncher
Running a Job
Running Jobs from the Command Line
The CommandLineJobRunner
ExitCodes
Running Jobs from within a Web Container
Advanced Meta-Data Usage
Querying the Repository
JobRegistry
JobRegistryBeanPostProcessor
AutomaticJobRegistrar
JobOperator
JobParametersIncrementer
Stopping a Job
Aborting a Job
5. Configuring a Step
Chunk-Oriented Processing
Configuring a Step
Inheriting from a Parent Step
Abstract Step
Merging Lists
The Commit Interval
Configuring a Step for Restart
Setting a StartLimit
Restarting a completed step
Step Restart Configuration Example
Configuring Skip Logic
Configuring Retry Logic
Controlling Rollback
Transactional Readers
Transaction Attributes
Registering ItemStreams with the Step
Intercepting Step Execution
StepExecutionListener
ChunkListener
ItemReadListener
ItemProcessListener
ItemWriteListener
SkipListener
SkipListeners and Transactions
TaskletStep
TaskletAdapter
Example Tasklet Implementation
Controlling Step Flow
Sequential Flow
Conditional Flow
Batch Status vs. Exit Status
Configuring for Stop
The 'End' Element
The 'Fail' Element
The 'Stop' Element
Programmatic Flow Decisions
Split Flows
Externalizing Flow Definitions and Dependencies Between Jobs
Late Binding of Job and Step Attributes
Step Scope
Job Scope
6. ItemReaders and ItemWriters
ItemReader
ItemWriter
ItemProcessor
Chaining ItemProcessors
Filtering Records
Fault Tolerance
ItemStream
The Delegate Pattern and Registering with the Step
Flat Files
The FieldSet
FlatFileItemReader
LineMapper
LineTokenizer
FieldSetMapper
DefaultLineMapper
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
IncorrectTokenCountException
IncorrectLineLengthException
FlatFileItemWriter
LineAggregator
PassThroughLineAggregator
Simplified File Writing Example
FieldExtractor
PassThroughFieldExtractor
BeanWrapperFieldExtractor
Delimited File Writing Example
Fixed Width File Writing Example
Handling File Creation
XML Item Readers and Writers
StaxEventItemReader
StaxEventItemWriter
Multi-File Input
Database
Cursor Based ItemReaders
JdbcCursorItemReader
Additional Properties
HibernateCursorItemReader
StoredProcedureItemReader
Paging ItemReaders
JdbcPagingItemReader
JpaPagingItemReader
IbatisPagingItemReader
Database ItemWriters
Reusing Existing Services
Validating Input
Preventing State Persistence
Creating Custom ItemReaders and ItemWriters
Custom ItemReader Example
Making the
ItemReader
Restartable
Custom ItemWriter Example
Making the
ItemWriter
Restartable
7. Scaling and Parallel Processing
Multi-threaded Step
Parallel Steps
Remote Chunking
Partitioning
PartitionHandler
Partitioner
Binding Input Data to Steps
8. Repeat
RepeatTemplate
RepeatContext
RepeatStatus
Completion Policies
Exception Handling
Listeners
Parallel Processing
Declarative Iteration
9. Retry
RetryTemplate
RetryContext
RecoveryCallback
Stateless Retry
Stateful Retry
Retry Policies
Backoff Policies
Listeners
Declarative Retry
10. Unit Testing
Creating a Unit Test Class
End-To-End Testing of Batch Jobs
Testing Individual Steps
Testing Step-Scoped Components
Validating Output Files
Mocking Domain Objects
11. Common Batch Patterns
Logging Item Processing and Failures
Stopping a Job Manually for Business Reasons
Adding a Footer Record
Writing a Summary Footer
Driving Query Based ItemReaders
Multi-Line Records
Executing System Commands
Handling Step Completion When No Input is Found
Passing Data to Future Steps
12. JSR-352 Support
General Notes Spring Batch and JSR-352
Setup
Application Contexts
Launching a JSR-352 based job
Dependency Injection
Batch Properties
Property Support
@BatchProperty
annotation
Property Substitution
Processing Models
Item based processing
Custom checkpointing
Running a job
Contexts
Step Flow
Scaling a JSR-352 batch job
Partitioning
Testing
13. Spring Batch Integration
Spring Batch Integration Introduction
Namespace Support
Launching Batch Jobs through Messages
Transforming a file into a JobLaunchRequest
The JobExecution Response
Spring Batch Integration Configuration
Example ItemReader Configuration
Available Attributes of the Job-Launching Gateway
Sub-Elements
Providing Feedback with Informational Messages
Asynchronous Processors
Externalizing Batch Process Execution
Remote Chunking
Remote Partitioning
A. List of ItemReaders and ItemWriters
Item Readers
Item Writers
B. Meta-Data Schema
Overview
Example DDL Scripts
Version
Identity
BATCH_JOB_INSTANCE
BATCH_JOB_EXECUTION_PARAMS
BATCH_JOB_EXECUTION
BATCH_STEP_EXECUTION
BATCH_JOB_EXECUTION_CONTEXT
BATCH_STEP_EXECUTION_CONTEXT
Archiving
International and Multi-byte Characters
Recommendations for Indexing Meta Data Tables
C. Batch Processing and Transactions
Simple Batching with No Retry
Simple Stateless Retry
Typical Repeat-Retry Pattern
Asynchronous Chunk Processing
Asynchronous Item Processing
Interactions Between Batching and Transaction Propagation
Special Case: Transactions with Orthogonal Resources
Stateless Retry Cannot Recover
Glossary