I'm implementing a multi-tenant system using Spring where each tenant has its own database. I have everything up and running.
I've extended "AbstractRoutingDataSource" and overridden "determineCurrentLookupKey" to determine which connection to use via the users domain/tenancy.
The "AbstractRoutingDataSource" is instantiated when the app loads and all the possible database connections are set there.
Here's my question -
Is there a way of dynamically adding additional connections to the AbstractRoutingDataSource? I want to be able to add additional tenants without restarting.
Any help would be greatly appreciated
Thanks
I am too late to this thread, but recently I needed to build a Saas style multi-tenant web app. Tenants needed to be added dynamically without requiring a server restart. So I shared my learnings here with a complete working example.
Yes You can do So, Here is complete project which explains very nicely about your requirement: Multi-tenancy: Managing multiple datasources with Spring Data JPA
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With