Exception in thread “OkHttp Dispatcher“ java.lang.NoClassDefFoundError: okhttp3/internal/Util

Exception in thread "OkHttp Dispatcher" java.lang.NoClassDefFoundError: okhttp3/internal/Util

依赖的包 版本不对

使用 4.9.3 即可:

<dependency>
           <groupId>com.squareup.okhttp3</groupId>
           <artifactId>okhttp</artifactId>
           <version>4.9.3</version>
        </dependency>

`java.lang.NoClassDefFoundError: cn/hutool/core/util/ObjectUtil` 表示在运行时找不到 Hutool 的 `ObjectUtil` 类,通常发生在使用 Hutool 工具库的方法时,但项目中未正确引入该依赖。 此类问题在 OkHttp 的上下文中出现,可能是因为某个网络请求组件或拦截器依赖了 Hutool 的某些工具类,但部署环境中缺失了 Hutool 的运行时库。因此,尽管问题抛出位置在 OkHttp 的线程中(如 OkHttp Dispatcher),其根本原因仍然是类路径中缺少 Hutool 的 JAR 文件。 为了解决该问题,需要在项目中显式引入 Hutool 的核心依赖。对于 Maven 项目,应在 `pom.xml` 中添加以下依赖: ```xml <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.8.22</version> </dependency> ``` 这样可以确保 `cn.hutool.core.util.ObjectUtil` 类被正确打包进最终的部署文件中,避免运行时类加载失败的问题[^4]。 此外,如果使用了 Hutool 的加密模块(如 `GlobalBouncyC` 类),还需要额外引入 Bouncy Castle 提供的依赖以避免其他 `NoClassDefFoundError`: ```xml <dependency> <groupId>org.bouncycastle</groupId> <artifactId>bcprov-jdk18on</artifactId> <version>1.72</version> </dependency> ``` 在构建部署包后,应验证 JAR 文件中是否包含 Hutool 的类文件,可以通过以下命令检查: ```bash jar tf your-application.jar | grep cn/hutool ``` 如果发现缺失相关类,则需检查构建插件(如 `maven-shade-plugin` 或 `spring-boot-maven-plugin`)的配置,确保所有依赖被正确打包[^2]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值