Class 未找到 com/google/common/util/concurrent/FutureFallback
Class not found com/google/common/util/concurrent/FutureFallback
当我尝试使用 DataStax Java Driver. I have read few answer on SO. Here 从 Java 连接到 Cassandra 时出现此错误,它在 Guava 19.0 中显示 com.google.common.util.concurrent.FutureFallback is deprecated
并自 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>
Class :
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.onHalfClose(ServerCalls.java:148)
at io.grpc.internal.ServerCallImpl$ServerStreamListenerImpl.halfClosed(ServerCallImpl.java:263)
at io.grpc.internal.ServerImpl$JumpToApplicationThreadServerStreamListener.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>
你可以做的是在 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 驱动程序的传递依赖关系被拉入。
当我尝试使用 DataStax Java Driver. I have read few answer on SO. Here 从 Java 连接到 Cassandra 时出现此错误,它在 Guava 19.0 中显示 com.google.common.util.concurrent.FutureFallback is deprecated
并自 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>
Class :
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.onHalfClose(ServerCalls.java:148)
at io.grpc.internal.ServerCallImpl$ServerStreamListenerImpl.halfClosed(ServerCallImpl.java:263)
at io.grpc.internal.ServerImpl$JumpToApplicationThreadServerStreamListener.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>
你可以做的是在 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 驱动程序的传递依赖关系被拉入。