The JobRepository is the persistence layer of Spring Batch. It records every job instance, job execution, step execution and execution context, and it is the component that makes restarts, duplicate-run protection and job monitoring possible. Without it a batch job could not resume after a failure or know whether a run with the same parameters had already completed.
Every job launched through JobLauncher and every step it runs reads and writes this metadata through the JobRepository. In Spring Batch 5 you pass it explicitly to the builders, and in a Spring Boot application it is auto-configured for you.
The repository persists metadata in six relational tables, created from the schema scripts shipped in spring-batch-core:
| Table | Content |
|---|---|
BATCH_JOB_INSTANCE | One row per logical job run, identified by job name plus identifying parameters. |
BATCH_JOB_EXECUTION | Each attempt to run an instance: status, exit code, start, end and last update times. |
BATCH_JOB_EXECUTION_PARAMS | The parameters of an execution. |
BATCH_JOB_EXECUTION_CONTEXT | The serialized job-level ExecutionContext. |
BATCH_STEP_EXECUTION | Per-step counters: read, write, filter, skip and commit counts, status and timings. |
BATCH_STEP_EXECUTION_CONTEXT | The serialized step-level ExecutionContext, used for restart state. |
A job instance is the combination of a job and its identifying parameters. If you start importJob with date=2026-11-16 and that instance already completed, Spring Batch throws JobInstanceAlreadyCompleteException instead of running it again. A failed instance can be restarted, creating a new execution of the same instance.
During a run, the framework updates the repository at defined points: before a job starts, at the start and end of each step, and at every chunk commit. For chunk-oriented steps the step execution context is saved inside the same transaction as the chunk, which is what lets a restarted step continue from the last committed chunk.
Readers such as JdbcCursorItemReader and FlatFileItemReader store their current position in the ExecutionContext. On restart the reader reads that value back and skips ahead. You can store your own state the same way:
Values placed in the context must be serializable, and the job-level context is shared across steps while each step has its own.
With Spring Boot you usually configure nothing: Boot creates a JDBC-backed JobRepository from your DataSource, and can initialise the schema. The relevant properties are:
initialize-schema accepts always, never and embedded (the default, which only creates tables for an embedded database). For production use never and manage the schema with Flyway or Liquibase.
Outside Boot, or when you need custom settings, @EnableBatchProcessing registers a default repository, and you can customise it through attributes such as dataSourceRef and transactionManagerRef. To build one by hand, use JobRepositoryFactoryBean:
The repository is then handed to the builders that define jobs and steps:
The JobBuilderFactory and StepBuilderFactory classes that older tutorials use were deprecated in Spring Batch 5 and removed afterwards, so use JobBuilder and StepBuilder as shown.
| Option | Persists across restarts | Typical use |
|---|---|---|
| JDBC repository on a production database | Yes | Production jobs that must be restartable and auditable. |
| JDBC repository on an embedded database such as H2 | Only while the JVM lives | Tests and local development. |
| Resourceless repository (available in Spring Batch 5.x) | No | Jobs that never restart and where metadata is not needed. |
The old MapJobRepositoryFactoryBean was removed in Spring Batch 5, so an embedded database is the standard replacement for tests. If several application instances share one repository database, the repository uses database-level locking and the create-job-execution isolation level to prevent two nodes from running the same instance at once.
Because everything is stored in tables, you can inspect jobs with plain SQL or through JobExplorer (read-only access) and JobOperator (start, stop, restart, abandon). Metrics and dashboards, including Spring Cloud Data Flow, are built on the same metadata.
Plan for cleanup: the tables grow with every execution, so archive or delete old rows on a schedule, and index the tables if you query them often.
Yes for tests and simple jobs, using an embedded database or the resourceless repository, but you lose restartability and history. A durable repository is needed for production jobs that must resume after a crash.
The job instance, defined by job name and identifying parameters, finished successfully and Spring Batch refuses to rerun it. Add a unique identifying parameter such as a timestamp or run id, or use a RunIdIncrementer.
Yes. Give the repository its own DataSource and transaction manager. Keeping metadata separate is common when the business database is read-only or very busy.
JobRepository reads and writes metadata and is used by the framework during execution. JobExplorer only reads, which makes it the right tool for dashboards and monitoring code.
JobRepository is the metadata store behind Spring Batch. It tracks job instances, executions, step progress and execution contexts, and it enables restart, duplicate-run protection and monitoring. In Spring Batch 5 pass it to JobBuilder and StepBuilder, let Boot configure it where possible, manage the schema yourself in production, and clean up old metadata regularly.