Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic Datasource using SpringBoot [duplicate]

I'm writing a Microservice using SpringBoot and I have a requirement to select the datasource dynamically. I will select the datasource based on the parameter. Each datasources will point to Oracle Database that has the same schema (same tables, triggers, stored procedures and etc). How can I implement this requirement?

like image 399
Norberto Enomoto Avatar asked Jan 25 '26 20:01

Norberto Enomoto


1 Answers

Configure all datasources at startup, then:

either:

a. Have a different repo class that implements each datasource, check the parameter before calling the corresponding repo.

b. Have one repo class that checks the parameter and uses the corresponding datasource for its queries.

like image 127
Artanis Avatar answered Jan 28 '26 10:01

Artanis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!