簡體   English   中英

如何在Spring Boot和Spring Data中使用兩個Cassandra數據源?

[英]How can I use two Cassandra datasources with Spring Boot and Spring Data?

是否可以通過使用Spring Boot和Spring Data將Spring Boot應用程序連接到兩個不同的Cassandra數據源?

我嘗試配置2個不同的數據源,但是Spring Boot選擇第一個,而忽略另一個。

謝謝

Spring Boot僅支持開箱即用的數據源,並且使用單個CassandraTemplate配置單個Session

從Spring Data 2.0開始, CassandraTemplate支持SessionFactory ,該SessionFactory可以將調用路由到不同的Cassandra Session 您需要對自己進行配置:

@Configuration
class MyConfig {

  @Bean
  CassandraTemplate cassandraTemplate(CassandraConverter converter) {
    SessionFactory factory = …;
    return new CassandraTemplate(factory, converter);
  }
}

您可能想看看AbstractRoutingSessionFactory來構建自己的Session路由器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM