org.apache.curator.framework.listen.ListenerContainer.addListener的解决方法
Posted 纵横千里,捭阖四方
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了org.apache.curator.framework.listen.ListenerContainer.addListener的解决方法相关的知识,希望对你有一定的参考价值。
最近将几个服务注册到网关,需要增加zookeeper的jar包,有个服务升级之后一直报如下的错误:
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.apache.curator.framework.listen.ListenerContainer.addListener(ListenerContainer.java:40)
The following method did not exist:
com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor()Lcom/google/common/util/concurrent/ListeningExecutorService;
The calling method's class, org.apache.curator.framework.listen.ListenerContainer, was loaded from the following location:
jar:file:/Users/liuqingchao/.m2/repository/org/apache/curator/curator-framework/2.9.1/curator-framework-2.9.1.jar!/org/apache/curator/framework/listen/ListenerContainer.class
The called method's class, com.google.common.util.concurrent.MoreExecutors, is available from the following locations:
jar:file:/Users/liuqingchao/.m2/repository/com/google/guava/guava/26.0-android/guava-26.0-android.jar!/com/google/common/util/concurrent/MoreExecutors.class
The called method's class hierarchy was loaded from the following locations:
com.google.common.util.concurrent.MoreExecutors: file:/Users/liuqingchao/.m2/repository/com/google/guava/guava/26.0-android/guava-26.0-android.jar
Action:
Correct the classpath of your application so that it contains compatible versions of the classes org.apache.curator.framework.listen.ListenerContainer and com.google.common.util.concurrent.MoreExecutors
看起来这里问题是找一个类没找到,根据提示是在:curator-framework/2.9.1/curator-framework-2.9.1.jar!/org/apache/curator/framework/listen/这个路径下找类ListenerContainer.class,没找到,然后后面提示com/google/guava/guava/26.0-android/guava-26.0-android里有这个类,此时试图修改exclude等来将类定向到guava,或者排除掉curator2.9.1,但是均已失败告终。
之后将curator升级到4.0.1,还是不解决问题,有些基础包还是依赖2.9.1,所以必须手动将其都升到4.0.1。
同时,根据同事的提示,将guava版本降低到20:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>
仍然解决不了问题。
其实上面的错误提示信息是有误导的,我们不应该让curator去使用guava里的类,而应该想办法将curator从2.9.1全部升级到4.0.1版本。
尝试了很多次,发现只要在zookeeper-discovery-starter前指定org.apache.curator的版本号就可以了。完整代码:
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-client</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>com.****</groupId>
<artifactId>zookeeper-discovery-starter</artifactId>
<version>spring-2.x-curator-4.0.1-1.1.RELEASE</version>
</dependency>
这种问题很多时候是试出来的,记录一下,后面遇到类似的就可以参考了。
以上是关于org.apache.curator.framework.listen.ListenerContainer.addListener的解决方法的主要内容,如果未能解决你的问题,请参考以下文章