【问题标题】:IllegalStateException in Java driver 3.0 for cassandra despite using shaded jar尽管使用了阴影 jar,但用于 cassandra 的 Java 驱动程序 3.0 中的 IllegalStateException
【发布时间】:2016-09-19 15:54:04
【问题描述】:

我正在尝试使用现在推荐的 datastax java 驱动程序 3.0 从 java 连接到 cassandra,但出现异常

Caused by: java.lang.IllegalStateException: Detected Guava issue #1635 which indicates that a version of Guava less than 16.01 is in use.  This introduces codec resolution issues and potentially other incompatibility issues in the driver.  Please upgrade to Guava 16.01 or later.
at com.datastax.driver.core.SanityChecks.checkGuava(SanityChecks.java:62)
at com.datastax.driver.core.SanityChecks.check(SanityChecks.java:36)
at com.datastax.driver.core.Cluster.<clinit>(Cluster.java:67)

我已经下载了zip文件并用maven编译mvn clean package -Dskiptests 在核心驱动程序的目标文件夹中,我找到了一个名为 java-driver-3.0/cassandra-driver-core-3.0.1-SNAPSHOT-shaded.jar 的 jar,我将它添加到我的项目库中。 尝试运行项目会出现上述异常。

尝试如下连接集群

private static Cluster CLUSTER;
private static Session SESSION;

public static Cluster createCluster() {
    CLUSTER = Cluster.builder().addContactPoint("127.0.0.1").build();
    SESSION = CLUSTER.connect();
    ResultSet rs = SESSION.execute("select release_version from system.local");
    Row row = rs.one();
    System.out.println(row.getString("relese_version"));
    return CLUSTER;
}

public static Cluster getCluster() {
    if (null == CLUSTER) {
        CLUSTER = createCluster();
    }
    return CLUSTER;
}

我怀疑解决方案是here,但我不知道我应该如何处理该 XML。我是 Maven 的新手,请放轻松。 最后,Hector 客户端是否支持 Cassandra 3.x,因为如果我无法解决上述问题,我不介意使用 hector。

【问题讨论】:

    标签: java maven cassandra datastax-java-driver


    【解决方案1】:

    java驱动的shaded配置只对netty库进行shading,guava没有。不为 guava 着色的主要动机是 java 驱动程序的公共 API 在许多地方公开了诸如 ListenableFutureTypeToken 之类的 guava 类。

    你是如何运行你的代码的?您使用的是maven exec:java 还是某种IDE?

    我的猜测是你的类路径中的某个地方存在一个早于 16.01 的番石榴库。验证可以使用哪个 jar 的一种方法是从中获取一个类并打印它的源位置。即你可以试试这个 ListenableFuture 这是番石榴库的一部分:

    System.out.println(ListenableFuture.class.getProtectionDomain().getCodeSource().getLocation().getPath());
    

    这将打印包含该类的 jar 的位置,即:

    /Users/username/.m2/repository/com/google/guava/guava/16.0.1/guava-16.0.1.jar
    

    最后,Hector 客户端是否支持 Cassandra 3.x,因为如果我无法解决上述问题,我不介意使用 hector。

    Hector 是 thrift 传输的客户端,该传输已被弃用,并将在 Cassandra 4.0 中删除。它不再是一个活跃的项目,所以我不建议使用它。

    【讨论】:

    • 很抱歉回复晚了。我试图将该代码添加到我的 ContextListener 的 contextInitialized 方法中,但它不会编译 IDE,甚至不会修复导入。我正在使用捆绑的 Netbeans 和 Glassfish。
    【解决方案2】:

    我终于发现解决方案就在眼前。如本页所述。请原谅我在不支持 js 的移动浏览器上的原始链接,但当我在桌面浏览器上时,我会适当地编辑这个答案。

    https://java.net/jira/browse/GLASSFISH-20850

    glassfish 4 包含 guava 14.0 jar,在编译期间显然比推荐给驱动程序的 guava 16.01 或更高版本更受青睐。在项目的文件选项卡中的 WEB-INF 目录下,找到 sun-web.XML 并更改条目

    重新启动服务器,错误应该会消失。

    【讨论】:

      猜你喜欢
      • 2021-05-09
      • 2016-10-06
      • 2021-09-03
      • 2016-08-04
      • 2017-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-28
      相关资源
      最近更新 更多