Spring Boot handle multiple MongoTemplates for Multi Cluster MongoDB

心已入冬 提交于 2021-01-29 17:44:11

问题


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.

My requirements:

  1. I wanted all Spring configuration in Java code/annotations. (I hate XML!)
  2. I wanted Spring to manage both the Mongo and MongoTemplate objects.
  3. 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!

来源:https://stackoverflow.com/questions/63686198/spring-boot-handle-multiple-mongotemplates-for-multi-cluster-mongodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!