Multiple Data Sources with same entity and repo

后端 未结 2 1517
栀梦
栀梦 2021-01-15 02:15

Currently working on a project where my Spring Boot project needs to leverage multiple data sources or schema in the same DB server. I have found several tutorials that te

相关标签:
2条回答
  • 2021-01-15 02:37

    Managed to resolve the issue by using https://github.com/wmeints/spring-multi-tenant-demo.

    Thanks @surya for your recommendation.

    0 讨论(0)
  • 2021-01-15 02:51

    You need to look at AbstractRoutingDataSource and use it.

    So if I need to search for User John Doe I have to go through Schema 1 and if I don't find him, move onto the next schema.

    Thus you need to search in first schema and if not found, then go on to next schema.

    In that example as given in the above link,

     CustomerContextHolder.setCustomerType(CustomerType.GOLD);
     List<Item> items = catalog.getItems();
     if(isEmpty(goldItems)){
      CustomerContextHolder.setCustomerType(CustomerType.SILVER);
      items = catalog.getItems();  
     }
    

    More details can be found in another qn here

    0 讨论(0)
提交回复
热议问题