spark报java.lang.NoSuchMethodError: io.netty.buffer.PooledByteBufAllocator.defaultNumHeapArena()I

spark2.4.6与scala2.11.12运行程序过程中,遇到了netty版本冲突或包缺失导致程序出现NoSuchMethodError异常,报错如下:

Exception in thread “main” java.lang.NoSuchMethodError: io.netty.buffer.PooledByteBufAllocator.defaultNumHeapArena()I

20/07/13 12:50:55 INFO SecurityManager: SecurityManager: authentication disabled; ui acls disabled; users  with view permissions: Set(lenovo); groups with view permissions: Set(); users  with modify permissions: Set(lenovo); groups with modify permissions: Set()
Exception in thread "main" java.lang.NoSuchMethodError: io.netty.buffer.PooledByteBufAllocator.defaultNumHeapArena()I

在这里插入图片描述

解决方法:

1.在系统命令行中进入到项目根目录,也就是pom文件所在的目录,运行命令mvn dependency:tree查看jar包依赖(用ctrl+F快速定位到io.netty),发现初步定位就是这两个jar包导致的冲突

D:\Software\java\WorkSpace\hrbutest>mvn dependency:tree

在这里插入图片描述
2.使用 标签剔除 spark-core 中所有的低版本的netty,在项目中的pom文件中的指定标签中添加依赖

<dependency>
      <groupId>org.apache.hadoop</groupId>
      <artifactId>hadoop-hdfs</artifactId>
      <version>${hadoop.version}</version>
      <!--将netty包排除-->
      <exclusions>
        <exclusion>
          <groupId>io.netty</groupId>
          <artifactId>netty</artifactId>
        </exclusion>
      </exclusions>
</dependency>

3.然后添加高版本netty依赖,最后运行程序,就不会报错了

<dependency>
      <groupId>io.netty</groupId>
      <artifactId>netty-all</artifactId>
      <version>4.1.18.Final</version>
</dependency>
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值