Skip to content

Commit 9deaa16

Browse files
committed
Add example for in-memory job repository with an embedded database
Resolves #4016
1 parent 6417065 commit 9deaa16

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

spring-batch-docs/asciidoc/job.adoc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,29 @@ semantics within the repository, and because the business logic might still be
764764
transactional (such as RDBMS access). For testing purposes many people find the
765765
`ResourcelessTransactionManager` useful.
766766

767+
[NOTE]
768+
====
769+
The `MapJobRepositoryFactoryBean` and related classes have been deprecated in v4 and are scheduled
770+
for removal in v5. If you want to use an in-memory job repository, you can use an embedded database
771+
like H2, Apache Derby or HSQLDB. There are several ways to create an embedded database and use it in
772+
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]:
773+
774+
[source, java]
775+
----
776+
@Bean
777+
public DataSource dataSource() {
778+
return new EmbeddedDatabaseBuilder()
779+
.setType(EmbeddedDatabaseType.H2)
780+
.addScript("/org/springframework/batch/core/schema-drop-h2.sql")
781+
.addScript("/org/springframework/batch/core/schema-h2.sql")
782+
.build();
783+
}
784+
----
767785
786+
Once you have defined your embedded datasource as a bean in your application context, it should be picked
787+
up automatically if you use `@EnableBatchProcessing`. Otherwise you can configure it manually using the
788+
JDBC based `JobRepositoryFactoryBean` as shown in the <<job.adoc#configuringJobRepository,Configuring a JobRepository section>>.
789+
====
768790

769791
[[nonStandardDatabaseTypesInRepository]]
770792
==== Non-standard Database Types in a Repository

0 commit comments

Comments
 (0)