gpt4 book ai didi

java - 找不到类 com/google/common/util/concurrent/FutureFallback

转载 作者:行者123 更新时间:2023-12-02 12:26:39 38 4
gpt4 key购买 nike

当我尝试使用 DataStax Java Driver 从 Java 连接到 Cassandra 时,出现此错误。我读过一些关于SO的答案。 Here它说 com.google.common.util.concurrent.FutureFallback 在 Guava 19.0 中已弃用,并自 Guava 20.0 以来已删除。因此,请勿使用 Guava 20.0 或更高版本。

此外,我正在使用 Pmml-Evaluator这需要 Guava 20.0。如果我删除连接到 Cassandra 的这段代码,我的代码可以正常工作。那么,我现在该如何解决这个问题呢?

Pom.xml 依赖项:

<dependencies>

<dependency>
<groupId>org.jpmml</groupId>
<artifactId>pmml-model</artifactId>
<version>1.3.4</version>
</dependency>

<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.48</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jpmml</groupId>
<artifactId>pmml-evaluator</artifactId>
<version>1.3.4</version>
</dependency>

<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty</artifactId>
<version>1.1.2</version>
</dependency>

<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>1.1.2</version>
</dependency>

<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>1.1.2</version>
</dependency>

<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
<version>4.1.8.Final</version>
</dependency>

<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.1.4</version>
</dependency>

</dependencies>

类别:

package com.cw.predictive;

import com.datastax.driver.core.Session;
import com.datastax.driver.core.Cluster;

public class CassandraSession {

private static Session session;

private CassandraSession(){}

public static Session getCassandraSessionInstance(String[] CONTACT_POINTS, int PORT){

if(session == null){
synchronized (Session.class) {
if(session == null){
try{
Cluster cluster = Cluster.builder()
.addContactPoints(CONTACT_POINTS).withPort(PORT)
.build();
session = cluster.connect();
}
catch(Exception ex) {
System.out.println("Error occurred");
return null;
}
}
}
}
return session;
}
}

错误:

Exception in thread "grpc-default-executor-0" java.lang.NoClassDefFoundError: com/google/common/util/concurrent/FutureFallback
at com.cw.predictive.CassandraSession.getCassandraSessionInstance(CassandraSession.java:18)
at com.cw.predictive.PredictiveScore$LeadScoreImpl.getLeadScore(PredictiveScore.java:136)
at com.cw.predicitivegrpc.LeadScoreGrpc$MethodHandlers.invoke(LeadScoreGrpc.java:234)
at io.grpc.stub.ServerCalls$1$1.onHalfClose(ServerCalls.java:148)
at io.grpc.internal.ServerCallImpl$ServerStreamListenerImpl.halfClosed(ServerCallImpl.java:263)
at io.grpc.internal.ServerImpl$JumpToApplicationThreadServerStreamListener$2.runInContext(ServerImpl.java:586)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:52)
at io.grpc.internal.SerializingExecutor$TaskRunner.run(SerializingExecutor.java:152)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: com.google.common.util.concurrent.FutureFallback
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 11 more

最佳答案

正如您所遇到的,Apache Cassandra 的 DataStax Java 驱动程序尚不支持 Guava 20 和 21(请参阅:JAVA-1328)。

但是,有一个working PR已针对 Guava 16.01、17.0、18.0、19.0、20.0 和 21.0 进行了测试,我们的目标是版本 3.2.0 进行此修复。

我刚刚注意到您共享的 pmml-evaluator 中的 pom.xml 显示了受支持的版本范围 [14.0, 20.0]:

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>[14.0, 20.0]</version>
</dependency>

您可以做的是将 Guava 作为 org.jpmml 中的依赖项排除,即:

<dependency>
<groupId>org.jpmml</groupId>
<artifactId>pmml-evaluator</artifactId>
<version>1.3.4</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>

这应该可以防止 guava 20.0 由于解决 pmml-evaluator 的依赖关系而被拉入,而 guava 16.01 将通过 java 驱动程序的传递依赖关系被拉入。

关于java - 找不到类 com/google/common/util/concurrent/FutureFallback,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42230100/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com