The JobRepository interface is the persistence layer of Spring Batch. It stores the metadata of every job and step run (instances, executions, parameters, status, counters and execution contexts), and the framework reads it back to prevent duplicate runs, decide what can be restarted and report what happened.
Without a JobRepository, a batch job would have no memory: it could not tell whether it already ran, where it failed or how many items it processed.
Spring Batch records its state in a set of metadata tables, which the repository reads and writes:
| Table | Holds |
|---|---|
BATCH_JOB_INSTANCE | A job name plus identifying parameters (the logical run) |
BATCH_JOB_EXECUTION | Each attempt: status, start and end time, exit code |
BATCH_JOB_EXECUTION_PARAMS | The parameters of each execution |
BATCH_STEP_EXECUTION | Per-step status and read, write, skip, commit and rollback counts |
BATCH_JOB_EXECUTION_CONTEXT and BATCH_STEP_EXECUTION_CONTEXT | Serialised state used for restart |
The repository interface exposes operations such as createJobExecution, update(JobExecution), add(StepExecution), getLastStepExecution and isJobInstanceExists. Application code rarely calls them directly; the framework does, at every step and chunk boundary.
When a job fails at step three, the repository holds the last committed ExecutionContext. On restart, completed steps are skipped and the failed step resumes from its saved position, for example the last row read by a JdbcCursorItemReader.
Before a launch, the JobLauncher asks the repository whether an instance with the same identifying parameters is running or complete. This is how JobExecutionAlreadyRunningException and JobInstanceAlreadyCompleteException are raised.
Because every run is persisted, you can query the history with JobExplorer or plain SQL: when a job ran, how long it took, how many items it skipped and why it failed.
With Spring Boot 3 and Spring Batch 5, the repository is auto-configured from your primary DataSource. The schema is created on startup only if you ask for it:
Use always for embedded databases and development. In production, create the tables with a migration tool such as Flyway or Liquibase using the schema script shipped in spring-batch-core (org/springframework/batch/core/schema-postgresql.sql and the equivalents for other databases), and set the property to never.
The repository is injected into builders, never created per job:
To change isolation level, table prefix or the data source used for metadata, extend DefaultBatchConfiguration and override the relevant methods. Spring Batch 5 recommends this over the older DefaultBatchConfigurer.
Extending DefaultBatchConfiguration replaces Boot's batch auto-configuration, so the class must provide whatever else you relied on. For tests you can use an in-memory database, and the older map-based MapJobRepositoryFactoryBean has been removed.
JobExplorer is the read-only companion of the repository. Use it for dashboards and admin endpoints, and JobRepository only for writes done by the framework.
BATCH_JOB_EXECUTION if you poll it often.Not in the supported way. Spring Batch needs a repository, and the usual choice is a relational database. For tests, use an embedded database such as H2.
JobRepository creates and updates metadata during a run. JobExplorer only reads it, which makes it the right tool for monitoring.
No. In Spring Boot 3, auto-configuration registers the repository and launcher. Adding @EnableBatchProcessing turns that auto-configuration off, so only use it when you want full manual control.
The repository marks completed steps in BATCH_STEP_EXECUTION, and a restart resumes from the failed one unless the step is configured with allowStartIfComplete(true).
The JobRepository is Spring Batch's memory. It persists instances, executions and execution contexts so jobs can be restarted, duplicate runs are blocked and history can be queried. Let Spring Boot configure it, manage the schema with migrations in production, and use JobExplorer for reading status.