From 9deaa1694507bf2825246de9198ed2100b00a7e0 Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Wed, 23 Feb 2022 13:47:22 +0100 Subject: [PATCH] Add example for in-memory job repository with an embedded database Resolves #4016 --- spring-batch-docs/asciidoc/job.adoc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/spring-batch-docs/asciidoc/job.adoc b/spring-batch-docs/asciidoc/job.adoc index 26f528836..bfe4cde83 100644 --- a/spring-batch-docs/asciidoc/job.adoc +++ b/spring-batch-docs/asciidoc/job.adoc @@ -764,7 +764,29 @@ semantics within the repository, and because the business logic might still be transactional (such as RDBMS access). For testing purposes many people find the `ResourcelessTransactionManager` useful. +[NOTE] +==== +The `MapJobRepositoryFactoryBean` and related classes have been deprecated in v4 and are scheduled +for removal in v5. If you want to use an in-memory job repository, you can use an embedded database +like H2, Apache Derby or HSQLDB. There are several ways to create an embedded database and use it in +your Spring Batch application. One way to do that is by using the APIs from link:$$https://docs.spring.io/spring-framework/docs/current/reference/html/data-access.html#jdbc-embedded-database-support$$[Spring JDBC]: +[source, java] +---- +@Bean +public DataSource dataSource() { + return new EmbeddedDatabaseBuilder() + .setType(EmbeddedDatabaseType.H2) + .addScript("/org/springframework/batch/core/schema-drop-h2.sql") + .addScript("/org/springframework/batch/core/schema-h2.sql") + .build(); +} +---- + +Once you have defined your embedded datasource as a bean in your application context, it should be picked +up automatically if you use `@EnableBatchProcessing`. Otherwise you can configure it manually using the +JDBC based `JobRepositoryFactoryBean` as shown in the <>. +==== [[nonStandardDatabaseTypesInRepository]] ==== Non-standard Database Types in a Repository