当我尝试使用DataStax Java Driver从Java连接到Cassandra时,我收到此错误。关于SO我几乎没有回答。 Here它在Guava 19.0中显示com.google.common.util.concurrent.FutureFallback is deprecated
并从Guava 20.0开始删除。因此,不要使用Guava 20.0或更高版本。
此外,我正在使用需要Guava 20.0的Pmml-Evaluator。如果我删除连接到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
答案 0 :(得分:10)
正如您所遇到的,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的依赖而被拉入,而番石榴16.01将通过java驱动程序的传递依赖而被拉入。