本文介绍了使用Spring Data Couchbase连接到不同的Couchbase集群的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种使用Spring Data Couchbase连接到两个单独的Couchbase集群的方法.查看文档和实现,尚不清楚如何执行此操作,我担心的是,如果具有两个扩展AbstractCouchbaseConfiguration的配置,则将导致bean名称冲突.看上去唯一接近的是使用RepositoryOperationsMapping为不同的存储库指定不同的模板.但是,这不符合我的需求,因为每个Couchbase配置都不会意识到其他配置.我现在看到的唯一方法是不使用AbstractCouchbaseConfiguration并设置自己的bean,或者覆盖AbstractCouchbaseConfiguration中的所有bean并提供新的bean名称.在每种情况下,我都将覆盖@EnableCouchbaseRepositories批注中的couchbase模板bean名称.但是,我不确定这是否行得通或是否有更好的选择.

I'm looking for a way to use Spring Data Couchbase to connect to two separate Couchbase clusters. Looking at the documentation and the implementation, it is not clear as how to do this and my concern is that there will be bean name conflicts if have two configurations that extend AbstractCouchbaseConfiguration. The only thing that looks close is to use the RepositoryOperationsMapping to specify different templates for different repositories. This however doesn't suit my needs as each of the Couchbase configurations will not be aware of the other. The only means i see of doing this now is to either not use AbstractCouchbaseConfiguration and setup my own beans or to override all the beans in AbstractCouchbaseConfiguration and provide new bean names. In each case, i would override the couchbase template bean name in the @EnableCouchbaseRepositories annotation. However, i'm not sure if this is going to work or if there is a better option.

这有可能吗?如果可以的话,我最好的选择是什么?

Is this possible and if so, what is the best route for me to take?

谢谢

推荐答案

您能否详细说明保证创建和连接到两个单独集群的用例?

Could you elaborate on the use case that warranted the creation and connection to two separate clusters?

最好的方法仍然是在现有的AbstractCouchbaseConfiguration中使用自定义名称定义新的ClusterBucketCouchbaseTemplate bean,然后在conf中使用configureRepositoryOperationsMapping()方法.基本上就像有关多个文档的文档中所述桶,但将第二个Cluster豆添加到混合中.

The best route here is still probably to define new Cluster, Bucket and CouchbaseTemplate beans, with custom names, in your existing AbstractCouchbaseConfiguration, and then use the configureRepositoryOperationsMapping() method in the conf. Basically like described in the doc about multiple buckets, but adding a second Cluster bean to the mix.

这篇关于使用Spring Data Couchbase连接到不同的Couchbase集群的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 17:55