The job repository is required to run spring batch but it is one of those things that requires a bit of work to actually deliver any value (e.g. setting up spring batch admin or writing your own ui). In practice in most projects that I've seen that use Spring Batch the job repository is purely a write only thing that tends to be ignored completely. You're required to have it, nobody ever looks at it. Digging around in tables using an sql client to find logs with errors, warnings, and stack traces, is not a thing if you set up logging properly and doing logging properly is a hard requirement for any serious server side business.

IMHO, making the job repository optional would be a good thing given that it adds a lot of complexity. Most projects simply don't need it. And most projects that do need it (e.g. multi node batch clusters) should probably be looking at other technologies as well that are actually intended to provide cross cluster state management (e.g. Zookeeper). Also, at that point you are probably better off looking at things like Spring Cloud, hadoop or similar solutions. Spring batch sort of is a stepping stone towards those kinds of solutions.

Some things to be aware off:

  • Spring batch will create and fill tables with information that you probably want in a different place than your production database.
  • If you do end up with spring batch tables in your production db (e.g. because provisioning an extra db for tables you fundamentally don't care about would be overkill), you'll probably want to make sure these tables are part of your db migration scripts.
  • You may also want to consider cleaning up data accumulated in these tables regularly, especially if you never actually do anything with it.
  • By default jobs can run only once, you actually have to configure them to be able to run multiple times. It actually stores in the job repository that it already ran and by default will do nothing if you run something a second time. This "feature" has caught me by surprise on multiple occasions. The solution is adding a .incrementer(new RunIdIncrementer()) to your jobs.
  • Spring batch assumes that your jobs and steps are going to be distributed in a cluster (even when that is never going to be a thing for most projects). Therefore, the job repository is effectively the only way to pass around information (via the execution contexts, which get persisted).
Answer from Jilles van Gurp on Stack Overflow
🌐
Spring
docs.spring.io › spring-batch › reference › job › configuring-repository.html
Configuring a JobRepository :: Spring Batch Reference
The following example shows how to customize a JDBC-based job repository through the attributes of the @EnableJdbcJobRepository annotation: ... @Configuration @EnableBatchProcessing @EnableJdbcJobRepository( dataSourceRef = "batchDataSource", transactionManagerRef = "batchTransactionManager", tablePrefix = "BATCH_", maxVarCharLength = 1000, isolationLevelForCreate = "SERIALIZABLE") public class MyJobConfiguration { // job definition }
Top answer
1 of 2
11

The job repository is required to run spring batch but it is one of those things that requires a bit of work to actually deliver any value (e.g. setting up spring batch admin or writing your own ui). In practice in most projects that I've seen that use Spring Batch the job repository is purely a write only thing that tends to be ignored completely. You're required to have it, nobody ever looks at it. Digging around in tables using an sql client to find logs with errors, warnings, and stack traces, is not a thing if you set up logging properly and doing logging properly is a hard requirement for any serious server side business.

IMHO, making the job repository optional would be a good thing given that it adds a lot of complexity. Most projects simply don't need it. And most projects that do need it (e.g. multi node batch clusters) should probably be looking at other technologies as well that are actually intended to provide cross cluster state management (e.g. Zookeeper). Also, at that point you are probably better off looking at things like Spring Cloud, hadoop or similar solutions. Spring batch sort of is a stepping stone towards those kinds of solutions.

Some things to be aware off:

  • Spring batch will create and fill tables with information that you probably want in a different place than your production database.
  • If you do end up with spring batch tables in your production db (e.g. because provisioning an extra db for tables you fundamentally don't care about would be overkill), you'll probably want to make sure these tables are part of your db migration scripts.
  • You may also want to consider cleaning up data accumulated in these tables regularly, especially if you never actually do anything with it.
  • By default jobs can run only once, you actually have to configure them to be able to run multiple times. It actually stores in the job repository that it already ran and by default will do nothing if you run something a second time. This "feature" has caught me by surprise on multiple occasions. The solution is adding a .incrementer(new RunIdIncrementer()) to your jobs.
  • Spring batch assumes that your jobs and steps are going to be distributed in a cluster (even when that is never going to be a thing for most projects). Therefore, the job repository is effectively the only way to pass around information (via the execution contexts, which get persisted).
2 of 2
0

Spring Batch JobRepository stores details of every batch job not just the current job. It does not matter how or who execute the job as long as the jobs share the same jobRepository config in your spring context it will persist the job details to the same database configured for the jobRepository.

<bean id="jobRepository"
        class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
        <property name="dataSource" ref="dataSourceName" />
</bean>
🌐
Spring
docs.spring.io › spring-batch › docs › current › api › org › springframework › batch › core › repository › JobRepository.html
JobRepository (Spring Batch 5.2.6 API)
Repository responsible for persistence of batch meta-data entities. ... Lucas Ward, Dave Syer, Robert Kasanicky, David Turanski, Michael Minella, Mahmoud Ben Hassine, Parikshit Dutta ... Save the StepExecution and its ExecutionContext. ... Save a collection of StepExecutions and each ExecutionContext. ... Create a JobExecution for a given Job and JobParameters.
🌐
Medium
medium.com › @embadi.satish › configuring-a-springbatchjoblauncher-using-spring-3-203fc5144eeb
Configuring a SpringBatchJobLauncher using Spring 3 | by Satish Embadi | Medium
February 15, 2024 - Configuring a SpringBatchJobLauncher using Spring 3 There are multiple implementations of the Job interface. However, these implementations are abstracted behind either the provided builders (for …
🌐
Baeldung
baeldung.com › home › spring › introduction to spring batch
Introduction to Spring Batch | Baeldung
December 24, 2024 - Spring Batch follows the traditional batch architecture, in which a job repository schedules and interacts with jobs.
🌐
GitHub
github.com › spring-projects › spring-batch › blob › main › spring-batch-core › src › main › java › org › springframework › batch › core › repository › JobRepository.java
spring-batch/spring-batch-core/src/main/java/org/springframework/batch/core/repository/JobRepository.java at main · spring-projects/spring-batch
package org.springframework.batch.core.repository; · import org.springframework.batch.core.job.JobExecution; import org.springframework.batch.core.job.JobInstance; import org.springframework.batch.core.job.parameters.JobParameters; import org.springframework.batch.core.launch.NoSuchJobException; import org.springframework.batch.core.step.NoSuchStepException; import org.springframework.batch.core.step.StepExecution; import org.springframework.batch.core.repository.explore.JobExplorer; import org.springframework.batch.infrastructure.item.ExecutionContext; import org.jspecify.annotations.Nullable; ·
Author   spring-projects
🌐
Manning
livebook.manning.com › concept › spring › job-repository-database
job-repository-database in spring - liveBook · Manning
liveBooks are enhanced books. They add narration, interactive exercises, code execution, and other features to eBooks.
🌐
Spring
docs.spring.io › spring-batch › docs › 5.1.0-RC1 › org › springframework › batch › core › repository › JobRepository.html
JobRepository (Spring Batch 5.1.0-RC1 API)
Repository responsible for persistence of batch meta-data entities. ... Lucas Ward, Dave Syer, Robert Kasanicky, David Turanski, Michael Minella, Mahmoud Ben Hassine, Parikshit Dutta ... Save the StepExecution and its ExecutionContext. ... Save a collection of StepExecutions and each ExecutionContext. ... Create a JobExecution for a given Job and JobParameters.
Find elsewhere
🌐
Medium
medium.com › @eddybayonne1 › spring-batch-now-supports-nosql-mongodb-as-jobrepository-1278d459facd
Spring Batch Now Supports NoSQL (MongoDB) as JobRepository | by Bayonne Sensei | Medium
April 10, 2025 - Spring Batch Now Supports NoSQL (MongoDB) as JobRepository Spring Batch has long been a go-to framework for batch processing jobs, but its reliance on relational databases for the `JobRepository` has …
🌐
GitHub
github.com › spring-projects › spring-batch › issues › 3780
Deprecate the Map-based JobRepository/JobExplorer implementations · Issue #3780 · spring-projects/spring-batch
September 16, 2020 - This is impossible with the Map-based job repository, as it provides a single clear() method to wipe the entire entities graph. It is, however, possible with an in-memory database (you can get a handle to the datasource and run any deletion query). In Spring Batch, we claim that you can run a job without a data source.
Author   spring-projects
🌐
Spring
docs.spring.io › spring-batch › docs › 5.0.2 › reference › html › job.html
Configuring and Running a Job
Job and Step implementations later use the same JobRepository for basic updates of the same executions during the running of a Job. The basic operations suffice for simple scenarios. However, in a large batch environment with hundreds of batch jobs and complex scheduling requirements, more advanced access to the metadata is required: Figure 6. Advanced Job Repository Access
🌐
Spring
spring.io › guides › gs › batch-processing
Getting Started | Creating a Batch Service
The job ends, and the Java API produces a perfectly configured job. In the step definition, you define how much data to write at a time. In this case, it writes up to three records at a time. Next, you configure the reader, processor, and writer by using the beans injected earlier. The last bit of batch configuration is a way to get notified when the job completes.
🌐
Spring
docs.spring.io › spring-batch › reference › whatsnew.html
What’s new in Spring Batch 6 :: Spring Batch Reference
Spring Batch 6.0 includes the following features and improvements: ... Before v6, the @EnableBatchProcessing annotation was tied to a JDBC-based infrastructure. This is not the case anymore. Two new annotations have been introduced to configure the underlying job repository: @EnableJdbcJobRepository and @EnableMongoJobRepository.
🌐
Medium
medium.com › @fullstacktips › spring-batch-demo-with-examples-998c41f938ac
Spring Batch Demo with examples|Java | by FullStackTips | Medium
August 4, 2023 - Get complete guide on Spring Batch with focus on annotations. Learn how to build and run batch jobs using tasklets, readers, processors, and writers. Optimize your batch processing with best practices and examples
🌐
Technology explained
alexandreesl.com › tag › jobrepository
jobrepository – Technology explained
JobRepository: Facade class that interface the access of the framework classes to the tables of the repository, it is through this class that jobs communicate the progress of its executions, thus ensuring that it could make his restart; Thanks to this mechanism of control, Spring provides a web application, developed in Java, which allows actions like view execution logs of batches and start / stop / restart jobs through the interface, called Spring Batch Admin.
🌐
Spring
docs.spring.io › spring-batch › docs › 3.0.x › reference › html › configureJob.html
4. Configuring and Running a Job
BATCH_JOB_EXECUTION and BATCH_STEP_EXECUTION are two examples. However, there are potential reasons to modify this prefix. If the schema names needs to be prepended to the table names, or if more than one set of meta data tables is needed within the same schema, then the table prefix will need to be changed: <job-repository id="jobRepository" table-prefix="SYSTEM.TEST_" />
🌐
Spring
docs.spring.io › spring-batch › docs › current › reference › html › index-single.html
Overview :: Spring Batch Reference
August 23, 2023 - The reference documentation is divided into several sections: · Background, usage scenarios, and general guidelines
🌐
Adictos al trabajo
adictosaltrabajo.com › inicio › tutoriales › introducción a spring batch
Introducción a Spring Batch - Adictos al trabajo
January 7, 2020 - Spring Batch nos propone un diseño ... ... JobRepository: es el componente encargado de la persistencia de metadatos relativos a los procesos tales como procesos en curso o estados de las ejecuciones....
🌐
Manning Publications
livebook.manning.com › book › spring-batch-in-action › chapter-2
Chapter 2. Spring Batch concepts · Spring Batch in Action
October 4, 2011 - This vocabulary is a great communication tool for us in this book but also for you, your team, and your own batch applications. We first explore Spring Batch’s services and built-in infrastructure components for batch applications: the job launcher and job repository.