最近项目需要使用elastic-job-lite来完成定时任务功能
引入对应的jar包后,包括guava 20.0版本。每次项目启动后报错:
com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor()Lcom/google/common/util/concurrent/ListeningExecutorService
具体报错信息如下:
***************************
APPLICATION FAILED TO START
***************************
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:41)
The following method did not exist:
com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor()Lcom/google/common/util/concurrent/ListeningExecutorService;
The method's class, com.google.common.util.concurrent.MoreExecutors, is available from the following locations:
jar:file:/Users/dushan/.m2/repository/com/google/guava/guava/30.1-jre/guava-30.1-jre.jar!/com/google/common/util/concurrent/MoreExecutors.class
The class hierarchy was loaded from the following locations:
com.google.common.util.concurrent.MoreExecutors: file:/Users/user/.m2/repository/com/google/guava/guava/30.1-jre/guava-30.1-jre.jar
其实根本原因就是因为java项目引入的jar包中,其中包含了多个版本的guava版本的jar包。
解决方法: 1.打开idea的terminal ,输入命令:查看jar包依赖
mvn dependency:tree
2.可以看到项目中guava版本:
2.根据这个依赖树,找到依赖guava包的jar包。 找到对应的jar包,配置maven的executions
对于我的项目而言,我是使用elastic-job-lite导致项目启动报错,并且报错的内容是guava的版本guava-30.1-jre.jar 那么我找到引用这个jar包的是nacos-client,解决方式如下
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
|