Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 如何在spring boot couchbase中配置多个bucket_Spring Boot_Couchbase - Fatal编程技术网

Spring boot 如何在spring boot couchbase中配置多个bucket

Spring boot 如何在spring boot couchbase中配置多个bucket,spring-boot,couchbase,Spring Boot,Couchbase,我是couchbase新手,使用couchbase 5.1。单个spring引导应用程序数据库配置仅采用单个bucket名称 是否可以在弹簧靴中连接到多个couchbase铲斗?如果是,我如何实施 这是我的密码 @Configuration @EnableCouchbaseRepositories(basePackages = {"com.example" }) public class MyCouchbaseConfig extends AbstractCouchbaseConfigurati

我是couchbase新手,使用couchbase 5.1。单个spring引导应用程序数据库配置仅采用单个bucket名称

是否可以在弹簧靴中连接到多个couchbase铲斗?如果是,我如何实施

这是我的密码

@Configuration
@EnableCouchbaseRepositories(basePackages = {"com.example" })
public class MyCouchbaseConfig extends AbstractCouchbaseConfiguration {

 @Override
 protected CouchbaseEnvironment getEnvironment() {
     CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder().connectTimeout(150000).build();
     return env;
 }

 @Override
 protected List < String > getBootstrapHosts() {
     return Arrays.asList("localhost");
 }

 @Override
 protected String getBucketName() {
     return "student";
 }

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

 @Override
 public String typeKey() {
     return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE;
 }

 }
@配置
@EnableCouchbaseRepositories(basePackages={“com.example”})
公共类MyCuchBaseConfig扩展了AbstractCouchbaseConfiguration{
@凌驾
受保护的CouchbaseEnvironment getEnvironment(){
CouchbaseEnvironment env=DefaultCouchbaseEnvironment.builder().connectTimeout(150000.build();
返回环境;
}
@凌驾
受保护列表getBootstrapHosts(){
返回Arrays.asList(“localhost”);
}
@凌驾
受保护的字符串getBucketName(){
返回“学生”;
}
@凌驾
受保护的字符串getBucketPassword(){
返回“123456”;
}
@凌驾
公共字符串typeKey(){
返回MappingCouchbaseConverter.TYPEKEY\u SYNCGATEWAY\u兼容;
}
}

您可以使用
com.couchbase.client.java.Cluster#openBucket
创建尽可能多的bucket,因此要添加另一个bucket,请使您的类如下所示:

@Configuration
@EnableCouchbaseRepositories(basePackages = {
 "com.example"
})
public class MyCouchbaseConfig extends AbstractCouchbaseConfiguration {


 /* ... ALL YOUR CODE FROM EARLIER ... */


 @Bean
 public Bucket anotherBucket() throws Exception {
  return couchbaseCluster().openBucket("bucket2", "password");
 }

 // if using repositories you need to create another template and
 // override the entity<->template mapping
 @Bean
 public CouchbaseTemplate anotherTemplate() throws Exception {
  CouchbaseTemplate template = new CouchbaseTemplate(
   couchbaseClusterInfo(), anotherBucket(),
   mappingCouchbaseConverter(), translationService());
  template.setDefaultConsistency(getDefaultConsistency());
  return template;
 }

 @Override
 public void configureRepositoryOperationsMapping(
  RepositoryOperationsMapping baseMapping) {
  try {
   baseMapping.mapEntity(AnotherEntity.class, anotherTemplate());
  } catch (Exception e) {
   //custom Exception handling
  }
 }

}
@配置
@EnableCouchbaseRepositories(basePackages={
“com.example”
})
公共类MyCuchBaseConfig扩展了AbstractCouchbaseConfiguration{
/*…您以前的所有代码*/
@豆子
public Bucket另一个Bucket()引发异常{
return couchbaseCluster().openBucket(“bucket2”,“password”);
}
//如果使用存储库,则需要创建另一个模板和
//重写entitytemplate映射
@豆子
public CouchbaseTemplate anotherTemplate()引发异常{
CouchbaseTemplate=新CouchbaseTemplate(
couchbaseClusterInfo(),另一个Bucket(),
mappingCouchbaseConverter(),translationService());
setDefaultConsistency(getDefaultConsistency());
返回模板;
}
@凌驾
public void configureRepositoryOperationsMapping(
RepositoryOperationsMapping(基本映射){
试一试{
baseMapping.mapEntity(AnotherEntity.class,anotherTemplate());
}捕获(例外e){
//自定义异常处理
}
}
}