You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JDK1.8+Log4j2.17.2兼容的Jersey版本及升级报错解决

问题解决:Log4j 2.17.2升级后Jersey 1.19的兼容性错误

错误原因

Jersey 1.19内置的ASM字节码处理库版本较旧(基于ASM 4.x),而Log4j 2.17.2依赖的是更高版本的ASM(9.x系列),两者版本冲突导致Jersey的注解扫描器在解析类文件时抛出IllegalArgumentException。

修复步骤

方案1:升级Jersey到兼容版本(推荐)

升级到Jersey 1.x的最终稳定版1.19.4,该版本内置了更新的ASM库,可解决与Log4j 2.17.2的版本冲突,且无需大幅修改现有代码:

  • 修改Maven中所有Jersey相关依赖的版本为1.19.4:
    <!-- 核心依赖示例 -->
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-core</artifactId>
        <version>1.19.4</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-servlet</artifactId>
        <version>1.19.4</version>
    </dependency>
    <!-- 其他Jersey模块(如jersey-server、jersey-client)同步升级版本 -->
    

方案2:排除Jersey内置ASM,统一使用高版本ASM(可选)

若暂时无法升级Jersey,可手动排除Jersey打包的旧ASM依赖,引入与Log4j 2.17.2匹配的ASM版本:

  1. 在每个Jersey依赖中排除内置的ASM包:
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-core</artifactId>
        <version>1.19</version>
        <exclusions>
            <exclusion>
                <groupId>com.sun.jersey.repackaged</groupId>
                <artifactId>jersey-repackaged-asm</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- 其他Jersey依赖重复上述排除操作 -->
    
  2. 添加兼容的ASM依赖:
    <dependency>
        <groupId>org.ow2.asm</groupId>
        <artifactId>asm</artifactId>
        <version>9.3</version>
    </dependency>
    <dependency>
        <groupId>org.ow2.asm</groupId>
        <artifactId>asm-commons</artifactId>
        <version>9.3</version>
    </dependency>
    
    注意:此方案可能存在Jersey内部API与高版本ASM不兼容的风险,仅作为临时过渡方案。

验证依赖状态

执行Maven命令检查依赖树,确保ASM版本统一,无冲突:

mvn dependency:tree | grep asm

兼容版本说明

  • Jersey 1.x系列:推荐使用1.19.4,它是Jersey 1.x的最后稳定版,完全兼容JDK 1.8与Log4j 2.17.2。
  • Jersey 2.x系列:若考虑迁移到新版Jersey,2.35是支持JDK 8的稳定版本,可与Log4j 2.17.2兼容,但需注意Jersey 2.x与1.x的API差异,需调整部分代码。

内容的提问来源于stack exchange,提问作者Megha Verma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 08:35:21