1

I am using Spring Batch in my application, till Spring 4 we could use Map based job repository so it didn't have DB dependency. But recently we migrated to Spring 6 in which Spring has removed Map based repository. This is from their documentation:

“Historically, Spring Batch provided a map-based job repository and job explorer implementations to work with an in-memory job repository. These implementations were deprecated in version 4 and completely removed in version 5. The recommended replacement is to use the JDBC-based implementations with an embedded database, such as H2, HSQL, and others”

I don't want my application to have any dependency on DB and due to some reason my organization is not letting me use in memory database. Is there any way we can remove this dependency on DB in Spring Batch for latest version.

I have tried using H2 and MySql. Both are working fine but not able to figure out a way to work without any JDBC.

Abhijit Sarkar
  • 21,927
  • 20
  • 110
  • 219
Rishabh
  • 43
  • 10
  • I don’t believe you can use Spring batch without a db. – Abhijit Sarkar Jun 08 '23 at 04:09
  • 2
    "due to some reason my organization is not letting me use in memory database" - that's your real problem. – httPants Jun 08 '23 at 05:05
  • So, with Spring 6 we cant use Spring Batch without DB?? – Rishabh Jun 08 '23 at 06:48
  • Its either memory or database, otherwise how would it keep track of the job statuses, metadata? Also look at https://stackoverflow.com/questions/25077549/spring-batch-without-persisting-metadata-to-database perhaps something might help – JCompetence Jun 08 '23 at 07:05
  • you "just" need to implement (and configure) [`JobRepository`](https://github.com/spring-projects/spring-batch/blob/main/spring-batch-core/src/main/java/org/springframework/batch/core/repository/JobRepository.java) ..and though it's "forbidden"/outdated/"deleted", i think we can *very good* lean on an older impl [e.g. v4.3.8](https://github.com/spring-projects/spring-batch/blob/4.3.8/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java) – xerx593 Jun 12 '23 at 07:08

1 Answers1

1

I don't want my application to have any dependency on DB and due to some reason my organization is not letting me use in memory database

If you don't want or can't use an in-memory database, then you have to provide your own implementation of the JobRepository interface and use it with your jobs and steps.

Mahmoud Ben Hassine
  • 28,519
  • 3
  • 32
  • 50