Home > other >  Spring Batch conditionnal database call
Spring Batch conditionnal database call

Time:02-13

I'm a big spring batch beginner, I'm a working on an app that needs to make a call to different DB depending on a condition.

Here's what's the app does: Read a flat file that contains credit and debit card numbers, then depending if the number is credit or debit I have to make a call to a database to get some info, then make csv file with that info. The thing is that there are two DB one for debit cards and another for credit cards.

My problem is that I'm having difficulty to configure the batch job for the conditional call to the DB. If there was only one database to call I could've done it easily but this is confusing me.

For now, I have done a card reader, that read the flat file, a processor that retrieves info from DB and a writer for the final csv. I don't really see how I could configure the processor to call a different DB since spring batch uses only one data source.

CodePudding user response:

you have to configure two different Datasources Beans and inject them both in your batch processor.

Then the rest is simple (if credit use the first bean, or use the second one)

see this link for multiple datasources.

And don't forget to annotate one of them as Primary. Spring Batch will generate all its SQL tables in the Primary datasource by default.

  • Related