本文介绍了Apache Curator TestingServer 创建抛出 java.lang.NoSuchMethodError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行一个 TestingServer 以便能够为其编写单元测试.

I am trying to just run a TestingServer to be able to write unit tests for it.

    val zkServer = new TestingServer(2182)
    println(zkServer.getPort)

我的 pom 有以下与 Curator 相关的依赖,我尝试过 4.2.0 和 4.3.0 版本,都抛出相同的错误:

My pom has the following dependencies related to Curator, I have tried version 4.2.0 and 4.3.0, both throw the same error:

    <dependency>
        <groupId>org.apache.curator</groupId>
        <artifactId>curator-framework</artifactId>
        <version>${apache.curator.version}</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/org.apache.curator/curator-recipes -->
    <dependency>
        <groupId>org.apache.curator</groupId>
        <artifactId>curator-recipes</artifactId>
        <version>${apache.curator.version}</version>
    </dependency>

    <dependency>
        <groupId>org.apache.curator</groupId>
        <artifactId>curator-test</artifactId>
        <version>${apache.curator.version}</version>
    </dependency>

抛出的错误是这样的:

Exception in thread "Thread-0" java.lang.NoSuchMethodError: org.apache.zookeeper.server.ZooKeeperServer.<init>(Lorg/apache/zookeeper/server/persistence/FileTxnSnapLog;IIILorg/apache/zookeeper/server/ZKDatabase;)V
at org.apache.curator.test.TestingZooKeeperMain$TestZooKeeperServer.<init>(TestingZooKeeperMain.java:265)
at org.apache.curator.test.TestingZooKeeperMain.internalRunFromConfig(TestingZooKeeperMain.java:226)
at org.apache.curator.test.TestingZooKeeperMain.runFromConfig(TestingZooKeeperMain.java:132)
at org.apache.curator.test.TestingZooKeeperServer$1.run(TestingZooKeeperServer.java:158)
at java.lang.Thread.run(Thread.java:748)

推荐答案

我认为 Curator 目前只兼容 zookeeper 3.5.x.我试图用 3.6.0 运行它.因此,切换到 3.5.x 的问题为我解决了这个问题.

I think Curator is only compatible with zookeeper 3.5.x right now. I was trying to run it with 3.6.0. Hence the problem switching to 3.5.x fixed the issue for me.

这篇关于Apache Curator TestingServer 创建抛出 java.lang.NoSuchMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-26 13:44