spring-bootspring-batch

Spring batch issue with multiple datasource | spring boot 3


I am facing an issue with spring batch job in a monolith application. In that application two different module have different databases and we need to write batch job in both the module. Now, since spring batch job expect a datasource bean with name datasource , it is getting impossible to write 2 batch jobs in single deployable application, within two different module connecting to different databases. I think spring batch has discontinued the batchconfigurer class which I can see as a possible solution in some stackoverflow answers.

Spring boot 3 is what I am using and spring batch is 5.1.x


Solution

  • In Spring Boot 3, you can mark the datasource that you want to use for Spring Batch with @BatchDataSource. Even if you have multiple datasources, the one marked with that annotation will be used for Spring Batch.