Multiple Data Sources with same entity and repo

后端 未结 2 1549
栀梦
栀梦 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: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 items = catalog.getItems();
     if(isEmpty(goldItems)){
      CustomerContextHolder.setCustomerType(CustomerType.SILVER);
      items = catalog.getItems();  
     }
    

    More details can be found in another qn here

提交回复
热议问题