java.lang.NoSuchMethodError: io.netty.channel.DefaultChannelId.newInstance()Lio/netty/channel/DefaultChannelId;

java.lang.NoSuchMethodError: io.netty.channel.DefaultChannelId.newInstance()Lio/netty/channel/DefaultChannelId;

我正在尝试使用 "software.amazon.awssdk" % "dynamodb" % "2.10.33" 我在 Play 框架 (Java) 上的项目。

以下是项目配置的简要说明

scalaVersion := "2.11.8"
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.14")
sbt.version=0.13.8

尝试从新包中排除 netty 依赖项

("software.amazon.awssdk" % "dynamodb" % "2.10.33").excludeAll(ExclusionRule(organization =  "io.netty"))

该项目与

配合得很好
"com.amazonaws" % "aws-java-sdk-core" % "1.10.52",
"com.amazonaws" % "aws-java-sdk-s3" % "1.10.52",
"com.amazonaws" % "aws-java-sdk-dynamodb" % "1.10.52"

升级到新的 AWS 库似乎中断了项目。 sbt compile returns 成功 但是,sbt run 会导致上述错误。

java.lang.NoSuchMethodError:
> io.netty.channel.DefaultChannelId.newInstance()Lio/netty/channel/DefaultChannelId;


[info] Running the application with Aspectj Weaver
--- (Running the application, auto-reloading is enabled) ---

java.lang.NoSuchMethodError: io.netty.channel.DefaultChannelId.newInstance()Lio/netty/channel/DefaultChannelId;
        at io.netty.channel.AbstractChannel.newId(AbstractChannel.java:100)
        at io.netty.channel.AbstractChannel.<init>(AbstractChannel.java:72)
        at io.netty.bootstrap.FailedChannel.<init>(FailedChannel.java:33)
        at io.netty.bootstrap.AbstractBootstrap.initAndRegister(AbstractBootstrap.java:308)
        at io.netty.bootstrap.AbstractBootstrap.doBind(AbstractBootstrap.java:260)
        at io.netty.bootstrap.AbstractBootstrap.bind(AbstractBootstrap.java:227)
        at play.core.server.NettyServer.bind(NettyServer.scala:139)
        at play.core.server.NettyServer.play$core$server$NettyServer$$bindChannel(NettyServer.scala:224)
        at play.core.server.NettyServer$$anonfun.apply(NettyServer.scala:216)
        at play.core.server.NettyServer$$anonfun.apply(NettyServer.scala:216)
        at scala.Option.map(Option.scala:146)
        at play.core.server.NettyServer.<init>(NettyServer.scala:216)
        at play.core.server.NettyServerProvider.createServer(NettyServer.scala:279)
        at play.core.server.NettyServerProvider.createServer(NettyServer.scala:278)
        at play.core.server.DevServerStart$$anonfun$mainDev.apply(DevServerStart.scala:235)
        at play.core.server.DevServerStart$$anonfun$mainDev.apply(DevServerStart.scala:65)
        at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
        at play.core.server.DevServerStart$.mainDev(DevServerStart.scala:64)
        at play.core.server.DevServerStart$.mainDevHttpMode(DevServerStart.scala:54)
        at play.core.server.DevServerStart.mainDevHttpMode(DevServerStart.scala)
        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 play.runsupport.Reloader$.startDevMode(Reloader.scala:234)
        at play.sbt.run.PlayRun$$anonfun$playRunTask$$anonfun$apply$$anonfun$apply.devModeServer$lzycompute(PlayRun.scala:74)
        at play.sbt.run.PlayRun$$anonfun$playRunTask$$anonfun$apply$$anonfun$apply.play$sbt$run$PlayRun$$anonfun$$anonfun$$anonfun$$devModeServer(PlayRun.scala:74)
        at play.sbt.run.PlayRun$$anonfun$playRunTask$$anonfun$apply$$anonfun$apply.apply(PlayRun.scala:100)
        at play.sbt.run.PlayRun$$anonfun$playRunTask$$anonfun$apply$$anonfun$apply.apply(PlayRun.scala:53)
        at scala.Function1$$anonfun$compose.apply(Function1.scala:47)

附加的依赖关系树: https://drive.google.com/file/d/1dVf8aJiv2i0Tscn2XEhETQ-ae3dgqfHk/view?usp=sharing

您正在尝试使用两个不兼容的 Netty 版本。那是不可能的。

升级到 Play 2.6 或更高版本可以解决此问题,原因有二:

  1. Play 2.6 默认使用 akka-http 作为服务器
  2. Play 2.6 中的 Netty 有阴影,所以你可以在你的项目中使用另一个依赖 Netty 的库

编辑:AWS SDK 仅使用 Netty 作为其默认的 http 客户端,可以更换。

libraryDependencies ++= Seq(
  "software.amazon.awssdk" % "dynamodb" % "2.10.33" exclude("software.amazon.awssdk", "netty-nio-client")
)