Spring Batch Reference
|
This section documents the current Spring Batch line — 6.0.x, on Spring Framework 7 and Spring Boot 4.1.x, with a Java 17+ baseline — as published at the Spring Batch reference documentation. No specific patch version is pinned. Some surfaces (Spring Cloud Task and Spring Cloud Data Flow orchestration, the deployer-based partition handler, and JSR-352) are linked, not documented in depth. This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
Welcome to the Spring Batch reference. Spring Batch is a lightweight
framework for finite, bounded bulk processing: it reads a large but known quantity of input, does something to
each item, and writes the result — transactionally, restartably, and with a full audit trail in a
JobRepository. Its domain language is a Job made of Step`s, and its workhorse is the chunk-oriented step
built from an `ItemReader, an ItemProcessor and an ItemWriter. It is deliberately not a scheduler: when a
job runs is left to cron, Quartz, an enterprise scheduler or a Kubernetes CronJob.
If you are new to Spring Batch, read What Spring Batch is & running a first job first, then Jobs, instances & parameters — which explains why parameters decide identity and how restart works — followed by Chunk-oriented processing. Everything after that builds on those three.
For the Spring Boot integration specifically — the spring-boot-starter-batch dependency, the auto-configured
job repository and datasource, the spring.batch.* properties and the JobLauncherApplicationRunner — see the
shorter sibling page Spring Batch (SpringBoot Reference), which these
pages cross-link rather than restate. For the persistence and SQL baselines the reader and writer pages build
on, see Spring Data JPA,
Hibernate Reference and SQL Reference.
What’s covered
Getting started
-
What Spring Batch is & running a first job — Spring Batch as a framework for finite, bounded bulk processing and explicitly not a scheduler, its origin and JSR-352 alignment, the module layout (
spring-batch-core,spring-batch-infrastructure,spring-batch-test,spring-batch-integration,spring-boot-starter-batch), the 6.0.x release line, and a first runnable tasklet job.
Architecture & domain language
-
Architecture & processing strategies — the application / core / infrastructure layering, general batch principles, and the processing strategies: the normal batch window, concurrent batch with online access and logical locking, parallel processing, and partitioning with its six break-up approaches.
-
Jobs, instances & parameters —
Job,JobInstanceas a job plus its identifyingJobParameters, typed and identifying/non-identifying parameters,JobExecutionwith theBatchStatuslifecycle andExitStatus, and running two executions of one instance. -
Steps, executions & the
ExecutionContext—StepandStepExecutionwith its read/write/commit/rollback/filter/skip counters, the job- and step-scopedExecutionContextand when each is persisted, and passing data between steps with anExecutionContextPromotionListener.
Configuring & running jobs
-
Infrastructure configuration — why
@EnableBatchProcessingis left off under Spring Boot, the 6.0 split into@EnableBatchProcessingplus@EnableJdbcJobRepository/@EnableMongoJobRepository,DefaultBatchConfigurationfor manual control, the resourceless defaults, and theJobRepository/JobExplorerandJobOperator/JobLauncherunification. -
The job repository & metadata schema — the six metadata tables and their sequences, the per-vendor DDL and
spring.batch.jdbc.*properties, the JDBC, MongoDB and resourceless repositories, the serializable isolation used when creating an execution, and querying run history. -
Configuring a job —
JobBuilder, step ordering, restartability and start limits,JobParametersValidator,JobParametersIncrementer, andJobExecutionListener. -
Running a job — the unified
JobOperator, synchronous versus asynchronous launching, Spring Boot’sJobLauncherApplicationRunner, the 6.0CommandLineJobOperator, and launching on demand from an endpoint, a scheduled method or Quartz. -
Stopping, restart & recovery — graceful stop and the 6.0
StoppableStep, failure andExitStatus, controlling restart, rerunning a completed step,JobOperator.recover()for stranded executions, and failing a step that read nothing.
Steps
-
Chunk-oriented processing — the read/process/write loop, the commit interval as chunk size and transaction boundary, dynamic sizing with a
CompletionPolicy, the 6.0ChunkOrientedStepBuilder, transaction attributes, and stream registration. -
Tasklet steps — the
Taskletcontract andRepeatStatus, transaction semantics, the adapter tasklets, and when a tasklet beats a chunk step. -
Fault tolerance: skip & retry —
.faultTolerant(), skip policies and listeners, retry on Spring Framework 7’s retry support, back-off,.noRollback(…), and the replay semantics that require an idempotent processor. -
Step flow & listeners — sequential and conditional transitions,
JobExecutionDecider, split flows, reusable flows andFlowStep, the listener interfaces and their annotations, and late binding with@StepScope/@JobScope.
`ItemReader`s, `ItemProcessor`s & `ItemWriter`s
-
ItemReader`s: files & XML/JSON— the reader contracts, `FlatFileItemReader and the tokenizer/FieldSet/mapper chain, multi-format and multi-line records,MultiResourceItemReader,StaxEventItemReader,JsonItemReader, and custom readers. -
`ItemReader`s: databases — cursor versus paging, the JDBC, JPA, Hibernate, stored-procedure and Spring Data readers, and the driving-query pattern.
-
`ItemProcessor`s — transformation and type change, filtering versus skipping, composing and routing processors, validation, and why a processor must be idempotent.
-
ItemWriter`s: files & XML/JSON— the writer contracts, `FlatFileItemWriter with its aggregator/extractor chain and header/footer callbacks, the file-management flags, XML and JSON writers, output rollover, and composing writers. -
ItemWriter`s: databases & alternative destinations— `JdbcBatchItemWriter and its parameter strategies, the JPA and Hibernate writers, the Spring Data writers, and the alternative-destination adapters. -
Repeat & retry internals —
RepeatOperations/RepeatTemplatewith completion policies and exception handlers,RetryOperations/RetryTemplate, stateless versus stateful retry, and how a step’s settings map onto them.
Scaling & tuning
-
Scaling & parallel processing — measuring first, then the multi-threaded step, parallel steps, the 6.0 producer/consumer model and local chunking, the async processor and writer, partitioning, and remote chunking and remote partitioning, with the restartability, ordering and durability trade-offs of each.
-
Profiling & tuning — profiling with VisualVM and Java Flight Recorder, choosing a chunk size, reader and writer costs,
saveState, keeping theExecutionContextsmall, the cost of metadata writes and indexing the metadata tables, and the common anti-patterns.
Integration, observability & cloud-native batch
-
Spring Batch Integration — launching jobs from messages, the async processor and writer, SEDA-style stage decoupling with blocking queues, and how remote chunking and remote partitioning are wired over `MessageChannel`s.
-
Observability — the
spring.batch.*Micrometer meters, tracing through the Observation API, the 6.0 Java Flight Recorder events, and what Spring Boot Actuator adds. -
Cloud-native batch — the twelve-factor lens on a batch application, externalized configuration, guarding remote calls with a circuit breaker, Spring Cloud Task and Spring Cloud Data Flow, and running batch on Kubernetes.
Testing
-
Testing batch jobs —
spring-batch-test,@SpringBatchTest,JobOperatorTestUtilsandJobRepositoryTestUtils,MetaDataInstanceFactory, testing step- and job-scoped beans, end-to-end assertions and output validation, and mocking — on JUnit Jupiter only.
Cheat sheet
-
Spring Batch Cheat Sheet — a single-page, colour-coded summary of the essentials, with a downloadable printable PDF.
Bibliography
-
Spring Batch Reference Documentation (6.0.x) — the source every page in this section is written and verified against; see in particular Spring Batch Introduction, What’s new in Spring Batch 6.0, Batch processing and Spring Batch’s architecture, The domain language of batch, Configuring and running a job, Configuring a step (including TaskletStep), ItemReaders and ItemWriters, Item processing, Scaling and parallel processing, Repeat, Retry, Unit testing, Common batch patterns, Spring Batch Integration, Spring Batch observability with Micrometer support and Java Flight Recorder support, Appendix A: meta-data schema, and the general appendix, glossary and FAQ.
-
Spring Boot — Batch Applications — Spring Boot’s batch support: the
spring-boot-starter-batchstarter, the auto-configured job repository stores, thespring.batch.*properties, and theJobLauncherApplicationRunnerthat runs jobs at startup. -
Spring Batch 6.0 Migration Guide — used to describe what changed relative to the 4.x-era APIs, including the removal of
JobBuilderFactory/StepBuilderFactory/BatchConfigurer, thejavax.tojakarta.move, the unifiedJobRepository/JobOperator, the move to Spring Framework retry, and the removal of JUnit 4 support. -
Spring Cloud Task and Spring Cloud Data Flow documentation — linked for the orchestration and deployment material on Cloud-native batch, which those projects document in depth.
-
Minella, Michael T. The Definitive Guide to Spring Batch: Modern Finite Batch Processing in the Cloud, 2nd ed. Apress, 2019. ISBN 978-1-4842-3723-6 (paperback) / 978-1-4842-3724-3 (eBook), DOI 10.1007/978-1-4842-3724-3. Foreword by Dave Syer. Publisher page: The Definitive Guide to Spring Batch. Consulted as part of the bibliography for this section. Its code targets Spring Boot 2.1.x / Spring Batch 4.x on Java 8 and uses the removed
@EnableBatchProcessing+JobBuilderFactory/StepBuilderFactory+BatchConfigureridiom andjavax.*imports, so where it and the official documentation disagree the official documentation is authoritative and the difference is noted on the page concerned.
The book above is a consulted bibliography reference only and is not the primary reference for this section: the official documentation at docs.spring.io/spring-batch wins on any discrepancy.