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, JobInstance as a job plus its identifying JobParameters, typed and identifying/non-identifying parameters, JobExecution with the BatchStatus lifecycle and ExitStatus, and running two executions of one instance.

  • Steps, executions & the ExecutionContext — Step and StepExecution with its read/write/commit/rollback/filter/skip counters, the job- and step-scoped ExecutionContext and when each is persisted, and passing data between steps with an ExecutionContextPromotionListener.

Configuring & running jobs

  • Infrastructure configuration — why @EnableBatchProcessing is left off under Spring Boot, the 6.0 split into @EnableBatchProcessing plus @EnableJdbcJobRepository/@EnableMongoJobRepository, DefaultBatchConfiguration for manual control, the resourceless defaults, and the JobRepository/JobExplorer and JobOperator/JobLauncher unification.

  • 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, and JobExecutionListener.

  • Running a job — the unified JobOperator, synchronous versus asynchronous launching, Spring Boot’s JobLauncherApplicationRunner, the 6.0 CommandLineJobOperator, and launching on demand from an endpoint, a scheduled method or Quartz.

  • Stopping, restart & recovery — graceful stop and the 6.0 StoppableStep, failure and ExitStatus, 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.0 ChunkOrientedStepBuilder, transaction attributes, and stream registration.

  • Tasklet steps — the Tasklet contract and RepeatStatus, 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 and FlowStep, 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/RepeatTemplate with 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 the ExecutionContext small, 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, JobOperatorTestUtils and JobRepositoryTestUtils, 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

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.