1

我的数据人员给了我http://127.0.0.1:8091/pools连接到我们的 Couchbase 服务器的 url,我被告知pools后缀是集群中所有节点的地址。

我使用 Spring 4.2.0.RELEASE 和 spring-data-couchbase 2.0.0.M1 对抗 Couchbase 2.5.1 企业版(build-1083)

现在,如果我将上面的 url 按原样添加到 getBootstrapHosts 列表中:

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

我的值出现数字格式异常8091/pools

但是当使用http://127.0.0.1:8091url 时,我得到一个无效的密码异常。

我认为第一个 url 将被使用,但不是我所采用的方式。

在 AbstractCouchbaseConfiguration 类中可能有一个我应该重写的方法,但是查看源代码并没有真正启发我。

这是 Couchbase 配置类。

@Configuration
@EnableCouchbaseRepositories(basePackages = { "com.thalasoft.data.couchbase.repository" })
@ComponentScan(nameGenerator = PackageBeanNameGenerator.class, basePackages = { "com.thalasoft.data.couchbase.config" })
@EnableTransactionManagement
public class CouchbaseConfiguration extends AbstractCouchbaseConfiguration {

  private static Logger logger = LoggerFactory.getLogger(CouchbaseConfiguration.class);

  @Autowired
  private CouchbaseProperties couchbaseProperties;

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

  @Override
  protected String getBucketName() {
    return couchbaseProperties.getBucketName();
  }

  @Override
  protected String getBucketPassword() {
    return couchbaseProperties.getBucketPassword();
  }

  @Bean
  public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
     return new PropertySourcesPlaceholderConfigurer();
  }

  @Bean
  public LocalValidatorFactoryBean validator() {
    return new LocalValidatorFactoryBean();
  }

  @Bean
  public ValidatingCouchbaseEventListener validationEventListener() {
    return new ValidatingCouchbaseEventListener(validator());
  }

}
4

1 回答 1

1

您的数据库管理员给您作为连接地址的事实127.0.0.1看起来很奇怪,但如果集群的一个节点与客户端代码在同一位置运行,则确实可能是有效的......

这种基于 url 的语法是用于1.4.x生成 SDK 的语法,配置确实有点不同2.x(反映了 Couchbase SDK 在 1.4.x 和 2.x 之间的演变):您只需要提供主机名或 ip从列表中引导的每个节点。

您应该尝试使用"127.0.0.1". 您也可能需要指定存储桶名称和/或密码(询问您的管理员)。Spring Data Couchbase 为每个使用的默认值是"default"and ""(空密码),但您可以覆盖getBucketName()andgetBucketPassword()方法AbsctractCouchbaseConfiguration来更改它。

PS:Spring Data Couchbase文档可在此处获得

于 2015-12-14T16:30:51.313 回答