1

在 Couchbase 文档中,以下是配置环境的示例。拥有多个存储桶会怎样?

@Configuration
public class Config extends AbstractCouchbaseConfiguration {

    @Override
    protected List<String> getBootstrapHosts() {
        return Collections.singletonList("127.0.0.1");
    }

    @Override
    protected String getBucketName() {
        return "beer-sample";
    }

    @Override
    protected String getBucketPassword() {
        return "";
    }
}

4

1 回答 1

0

对于2.0.x分支中的多个存储桶,它当前的工作方式是您必须实例化第二个Bucketbean 和关联CouchbaseTemplate的(这是最难的部分):

//we want all User objects to be stored in a second bucket
//let's define the bucket reference...
@Bean
public Bucket userBucket() {
  return couchbaseCluster().openBucket("users", "");
}

//... then the template (inspired by couchbaseTemplate() method)...
@Bean
public CouchbaseTemplate userTemplate() {
  CouchbaseTemplate template = new CouchbaseTemplate(
    couchbaseClusterInfo(), //reuse the default bean
     userBucket(), //the bucket is non-default
    mappingCouchbaseConverter(), translationService() //default beans here as well
  );
  template.setDefaultConsistency(getDefaultConsistency());
  return template;
}

之后,您可能还希望您的一些存储库使用第二个模板(和存储桶)。RepositoryOperationsMapping目前也2.0.0-RC有一个实现(

于 2015-11-11T16:17:36.590 回答