【问题标题】:Guava version 16.0 being used during runtime even though 18.0 is used during compile timeGuava 版本 16.0 在运行时使用,即使在编译时使用 18.0
【发布时间】:2026-02-11 16:05:02
【问题描述】:

我正在尝试在 Wildfly 中运行一个项目。以下是番石榴依赖版本。我尝试在依赖管理中包含 18.0,但它仍然使用 16.0。整天都在为此苦苦挣扎,用谷歌搜索了很多,但没有解决方案。

这是堆栈跟踪

Caused by: java.lang.ExceptionInInitializerError
    at com.verizon.fieldops.equipmentservice.dao.cassandra.CassandraDAO.init(CassandraDAO.java:155)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:363)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:307)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136)
    ... 39 more
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:68)
    ... 47 more

作为评论中的请求,编辑描述以添加 pom 文件内容

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.verizon.fieldops</groupId>
    <artifactId>equipmentservice</artifactId>
    <version>1.00.004</version>
    <packaging>war</packaging>

    <name>equipmentservice</name>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.7.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <maven.test.skip>true</maven.test.skip>
        <libs.path>${basedir}/libs</libs.path>
    </properties>

    <dependencies>

        <!-- Spring Boot Web dependency -->
         <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Spring Boot Devtools -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>

        <!-- Spring Boot test framework -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>com.vaadin.external.google</groupId>
                    <artifactId>android-json</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Java JMS API dependency -->
        <dependency>
        <groupId>javax.jms</groupId>
        <artifactId>javax.jms-api</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Spring JMS dependency -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jms</artifactId>
    </dependency>

        <!-- OmegaCore Dependency -->
        <dependency>
            <groupId>com.verizon.fieldops</groupId>
            <artifactId>OmegaCore</artifactId>
            <version>1.00.006</version>
            <scope>system</scope>
            <systemPath>${libs.path}/OmegaCore-1.00.006.jar</systemPath>
        </dependency>

        <!-- <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency> -->

        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20180813</version>
        </dependency>


        <!-- JSR Annotations -->
        <dependency>
            <groupId>com.google.code.findbugs</groupId>
            <artifactId>jsr305</artifactId>
            <version>3.0.0</version>
            <scope>provided</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
            <exclusions>
                <exclusion>
                <groupId>org.apache.tomcat</groupId>
                <artifactId>tomcat-jdbc</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.datastax.cassandra</groupId>
            <artifactId>cassandraDependency</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${libs.path}/cassandraDependency-1.0.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>com.datastax.cassandra</groupId>
            <artifactId>cassandra-driver-core</artifactId>
            <version>3.0.1</version><!--$NO-MVN-MAN-VER$-->
            <scope>system</scope>
            <systemPath>${libs.path}/cassandra-driver-core-3.0.1.jar</systemPath>
        </dependency>

        <!-- Hystrix (Circuit Breaker) dependencies -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
            <version>1.4.7.RELEASE</version>
        </dependency>

    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Finchley.M9</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <!-- <finalName>MSTemplate</finalName> -->
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <!-- <version>3.2.2</version> -->
                <configuration>
                    <!-- <includeSystemScope>true</includeSystemScope> -->
                    <webResources>
                        <resource>
                            <directory>libs/</directory>
                            <targetPath>WEB-INF/lib</targetPath>
                            <includes>
                                <include>**/*.jar</include>
                            </includes>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <!-- Repositories -->
    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/libs-milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>

    <description>Equipment service</description>
</project>

【问题讨论】:

  • 你在使用maven/gradle吗?
  • 我正在使用 maven
  • 你能粘贴你的 pom 文件吗?
  • 在描述中添加了pom文件
  • 我在你的 pom 中没有看到番石榴

标签: spring-boot wildfly pom.xml netflix


【解决方案1】:

这让我想起了很久以前使用 Glassfish4 时的类加载问题。从 docs 开始,类将首先从以下顺序加载,然后再从 WAR 中的 lib 加载:

(1) 系统依赖项 - 这些是添加到 由容器自动生成的模块,包括 Java EE api。

(2) 用户依赖项 - 这些是通过添加的依赖项 jboss-deployment-structure.xml 或者通过 Dependencies: manifest 进入。

其中还提到了(1)中的依赖可以通过使用jboss-deployment-structure.xml来排除。

this开始,jboss-deployment-structure.xml应该放在/WEB-INF/里面,可以防止服务器自动添加一些依赖:

<jboss-deployment-structure>


     <!-- Exclusions allow you to prevent the server from automatically adding some dependencies     -->
    <exclusions>
        <module name="com.google.guava" />
    </exclusions>

</jboss-deployment-structure>

其实我不知道如何找到Guava模块的模块名称,我只是搜索了文档和Github,发现有一个叫com.google.guava

我也不确定它是否会起作用。但希望能给你一些方向。祝你好运。

【讨论】:

  • 这不是必需的,因为 WildFly 实现 jar 通常对应用程序不可见 - 只有 Java EE api 可见。
  • 你是如何学习spring的?我正在尝试学习spring,但到目前为止失败了。我需要你的帮助。你能给我一些资源来学习它吗?我真的需要帮助。我想在春天学习创建一个网站@KenChan
  • 嗨史蒂夫,但这是我从 WildFly 文档中读到的,有时它会先加载 WildFly 提供的 JAR,然后再从 WAR 加载 lib
  • @Pie ,我记得我读过一本叫《spring in action》的书,回到我学习春天的时候。查看官方文档也提供了一些资源。在我对 Spring 有了一个不错的概述知识之后,我喜欢查看源代码..
【解决方案2】:

查看名为archaius-core 0.7 5的依赖项当前正在使用guava version 16.0,那么如果您想使用guava version 18.0 您需要通过以下方式添加依赖项:

<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>18.0</version>
</dependency>

我认为这是打包你所拥有的 jar 时版本错字的问题。

【讨论】:

  • Even ,hystrix javanica 1.5.2 使用的是较旧的 guava 版本,即 15 0 mvnrepository.com/artifact/com.netflix.hystrix/hystrix-javanica/…
  • 我添加了依赖,但它仍然没有考虑它。不知何故,cassandra jar 和 hysterix jar 不能一起工作
  • 但是从Abdus的截图来看,他现在已经在使用guava 18.0了……
  • @AbdusSamad 是的,也许 Cassandra 和 hystrix 版本不兼容,这可能是问题所在。
  • @KenChan 是的。正如我提到的,打包 jar 版本时可能会出现一些拼写错误。我需要说明他所做的事情