The spring-boot-starter-batch dependency adds Spring Batch to a Spring Boot application, a framework for reliable, restartable batch processing of large volumes of data. It provides jobs, steps, chunk-oriented readers, processors and writers, and a job repository that records progress in a database.
Spring Boot auto-configures the infrastructure and, by default, runs your jobs when the application starts. You focus on the job definition instead of transaction handling, restart logic and metadata tables.
Batch processing means working through a large amount of data without user interaction: importing CSV files, nightly report generation, data migration or sending bulk emails. Typical needs are the same each time: process in chunks, skip or retry bad records, restart a failed run where it stopped, and keep an audit trail. Spring Batch supplies those building blocks.
| Concept | Meaning |
|---|---|
Job | The whole batch process, made of one or more steps |
Step | An independent phase, either chunk-oriented or a single Tasklet |
ItemReader | Reads one item at a time (file, database, queue) |
ItemProcessor | Transforms or filters an item |
ItemWriter | Writes a chunk of items |
JobRepository | Stores job and step execution state |
JobLauncher | Starts a job with JobParameters |
Adding the dependency gives you the following through auto-configuration:
JobRepository, backed by the DataSource you configure, with the Spring Batch metadata tables.JobLauncher and a JobExplorer for starting and querying executions.spring.batch.jdbc.initialize-schema.Job beans on startup, controlled by spring.batch.job.enabled.In Spring Boot 3 and later, which use Spring Batch 5, you should not add @EnableBatchProcessing. Adding it switches off Boot's auto-configuration. A database is required for the job repository; for quick experiments add an in-memory database such as H2.
This example reads names from a list, converts them to upper case in a processor and prints them in chunks of two. In a real job you would use a FlatFileItemReader or JdbcCursorItemReader and a database or file writer.
Running the application prints:
Each chunk of two items is read, processed and written in one transaction. If a chunk fails, only that transaction is rolled back, and a restart continues from the last committed chunk. The builder signatures above are those of Spring Batch 5; Spring Batch 6, used by newer Spring Boot generations, changes some details, so check the reference for your version.
By default every Job bean runs at startup. These properties control that:
To launch a job programmatically, inject the JobLauncher and pass unique parameters. A job instance is identified by its name and parameters, and Spring Batch refuses to re-run a completed instance with the same parameters:
A step can tolerate bad data and transient errors:
Skipped items are counted in the step execution, and a failed job can be restarted from its last successful chunk because the progress lives in the job repository tables.
Yes, the job repository stores metadata in a relational database. An embedded database works for tests and demos, but production should use a durable one.
Not with Spring Boot 3 and later. Boot configures Spring Batch automatically, and the annotation turns that off.
Set spring.batch.job.enabled=false and start jobs through a JobLauncher, a scheduler or an endpoint.
A tasklet runs one piece of work, such as deleting temporary files. A chunk step reads, processes and writes many items in transactional batches.
The spring-boot-starter-batch dependency provides Spring Batch with Boot auto-configuration: a job repository, a launcher and startup execution. Define jobs from steps built with readers, processors and writers, tune chunk size and fault tolerance, and use the repository for restart and auditing of large data workloads.