I have to implement multi-tenancy using spring-boot, mongodb. Previously I was using same cluster so things were simple enough. Now each tenant would have its own database in its own cluster. So I was thinking of having multiple mongoTemplates managed in a single application.
- I wanted all Spring configuration in Java code/annotations. (I hate XML!)
- I wanted Spring to manage both the Mongo and MongoTemplate objects.
- I wanted to use MongoRepository Interface beans and have the correct MongoTemplate back it.
Also I am looking for that once the request comes in ( I am already getting client ID ) then correct mongoTemplate is injected to be used throughout application.
Could anyone provide some sample code or working example for this? Any help is greatly appreciated. Thanks!