使用Spring-boot XML配置的Couchbase 5.0

时间:2018-02-06 08:22:51

标签: spring-boot couchbase spring-data-couchbase

如何使用couchbase 5.0 Spring启动XML配置?

全文: 最近,将couchbase服务器从4.0.0-4051升级到5.0.0 build 3519 (两者都是社区版) 。 Couchbase 4.0是基于存储桶的授权,couchbase 5.0成为基于角色的访问控制(RBAC)。 (用户可以访问特定的存储桶)。 我有一个Spring-boot应用程序,所有配置都是通过XML bean。它与couchbase 4.0完美配合,但当我更改为couchbase 5.0时(注意所有凭据都是正确的)我收到以下错误:

  

引起:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为'userServiceImpl'的bean时出错:通过字段'userRepo'表示的不满意的依赖关系;嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有名为'couchbaseRepositoryOperationsMapping'的bean可用       在org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)       在org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)       在org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)       at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:306)       在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)       在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)       在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)       在org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)       在org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)       在org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)       at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)       ......还有25个   引起:org.springframework.beans.factory.NoSuchBeanDefinitionException:没有名为'couchbaseRepositoryOperationsMapping'的bean可用       在org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:687)       在org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1207)       在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284)       在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)       在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:296)       在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)       在org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)       在org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)       在org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)       at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)       ......还有38个

我的依赖关系是:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.5.RELEASE</version>
</parent>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-couchbase</artifactId>
</dependency>

我可以通过手动的couchbase客户端配置(我已经做了一个样本并经过测试)来解决这个问题。通过这段代码(如https://blog.couchbase.com/new-sdk-authentication/所述):

Cluster cluster = CouchbaseCluster.create(); cluster.authenticate("username", "password"); Bucket bucket = cluster.openBucket("bucket-name");

(如果此处所需的来源为https://github.com/mashhur/twitter_blockchain

无论如何,XML选项将非常感谢!

1 个答案:

答案 0 :(得分:0)

使用Spring Boot和Spring Data提供更好的RBAC支持。这是当前的里程碑,应该很快就会发布!请参阅针对Kay SR6和Lovelace M2的DATACOUCH-322

另外,请注意,只需创建名称与存储桶名称相同的用户,即可使5.0的行为与早期版本相同。