NoSuchMethodError Couchbase 2.5.8 Spring Boot启动错误

时间:2018-05-18 10:51:12

标签: spring couchbase

我们在Spring启动应用程序(微服务)中使用Couchbase DB,它在PCF和应用程序崩溃启动期间产生NoSuchMethodError

使用的Couchbase SDK是2.5.8

            <dependency>
                <groupId>com.couchbase.client</groupId>
                <artifactId>java-client</artifactId>
                <version>2.5.8</version>
            </dependency>

并且RxJava版本是1.1.10。

使用以下代码

创建CouchbaseEnvironment
            CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder()
            .sslEnabled(true).bootstrapHttpSslPort(18091)
            .sslKeystoreFile(Preconditions.checkNotNull(environment.getProperty("couchbase.ssl.keystore")))
            .sslKeystorePassword(Preconditions.checkNotNull(environment.getProperty("couchbase.ssl.keystore.password")))
            .connectTimeout(50000)
            .kvTimeout(50000)
            .build();

我们得到的例外如下

            2018-05-18T16:02:56.889+05:30 [APP/PROC/WEB/0] [OUT] Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.couchbase.client.java.env.DefaultCouchbaseEnvironment]: Factory method 'couchbaseEnvironment' threw exception; nested exception is java.lang.NoSuchMethodError: com.couchbase.client.java.env.DefaultCouchbaseEnvironment$Builder.kvEndpoints(I)Lcom/couchbase/client/java/env/DefaultCouchbaseEnvironment$Builder;
            2018-05-18T16:02:56.889+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
            2018-05-18T16:02:56.889+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
            2018-05-18T16:02:56.889+05:30 [APP/PROC/WEB/0] [OUT] ... 26 common frames omitted
            2018-05-18T16:02:56.889+05:30 [APP/PROC/WEB/0] [OUT] Caused by: java.lang.NoSuchMethodError: com.couchbase.client.java.env.DefaultCouchbaseEnvironment$Builder.kvEndpoints(I)Lcom/couchbase/client/java/env/DefaultCouchbaseEnvironment$Builder;
            2018-05-18T16:02:56.889+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration$CouchbaseConfiguration.initializeEnvironmentBuilder(CouchbaseAutoConfiguration.java:102) ~[spring-boot-autoconfigure-1.5.8.RELEASE.jar!/:1.5.8.RELEASE]
            2018-05-18T16:02:56.889+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration$CouchbaseConfiguration.couchbaseEnvironment(CouchbaseAutoConfiguration.java:64) ~[spring-boot-autoconfigure-1.5.8.RELEASE.jar!/:1.5.8.RELEASE]

尝试使用Spring引导中可用的依赖项,但随后获得Time Out异常。

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-couchbase</artifactId>
            </dependency>

Couchbase存储桶在PCF中创建为服务,并在服务中进行绑定。

            [org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfiguration$CouchbaseConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.couchbase.client.java.Bucket]: Factory method 'couchbaseClient' threw exception; nested exception is java.lang.RuntimeException: java.util.concurrent.TimeoutException
            2018-05-18T12:46:22.497+05:30 [APP/PROC/WEB/0] [OUT] 2018-May-18 07:16:22.496 WARN [cb-io-1-1] c.c.c.c.e.Endpoint - [null][KeyValueEndpoint]: Generic Failure.
            2018-05-18T12:46:22.505+05:30 [APP/PROC/WEB/0] [OUT] 2018-May-18 07:16:22.504 WARN [cb-io-1-1] c.c.c.c.e.Endpoint - null
            2018-05-18T12:46:22.520+05:30 [APP/PROC/WEB/0] [OUT] 2018-May-18 07:16:22.519 WARN [cb-io-1-1] c.c.c.d.i.n.u.c.DefaultPromise - An exception was thrown by com.couchbase.client.core.endpoint.AbstractEndpoint$4$1.operationComplete()

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:0)

您可能还需要将core-io升级到1.5.6或更高版本。

<dependency>
    <groupId>com.couchbase.client</groupId>
    <artifactId>core-io</artifactId>
    <version>1.5.8</version>
</dependency>

NoSuchMethodError因为this change已经提交而被抛出。

另见: https://issues.couchbase.com/browse/JVMCBC-495

答案 1 :(得分:0)

该问题是由于Spring Cloud依赖性所致。我们组织的PCF已升级到最新版本的Spring Cloud Dependencies,一旦我升级到最新版本,它就可以正常工作

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.RC2</spring-cloud.version>
    </properties>

我以前使用的是以下版本

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.8.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Dalston.SR4</spring-cloud.version>
    </properties>

一旦我更新了这些依赖项,它便开始工作。