java.lang.NoSuchMethodError:'无效的akka. actor. ExtensionId,$init$(akka.actor.ExtensionId)'

vfh0ocws  于 2022-11-05  发布在  Java
关注(0)|答案(1)|浏览(146)

我只是尝试使用akka在scala项目中实现一个小的示例REST端点。

import akka.http.scaladsl.Http
import akka.http.scaladsl.model.{ContentTypes, HttpEntity}

import akka.actor.typed.ActorSystem
import akka.actor.typed.scaladsl.Behaviors
import scala.io.StdIn

import scala.concurrent.ExecutionContextExecutor

object ViewAPI :
  @main def run(): Unit = {
    implicit val system = ActorSystem(Behaviors.empty, "my-system")
    implicit val executionContext = system.executionContext
    val route =
      path("hello") {
        get {
          complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, "<h1>Say hello to akka-http</h1>"))
        }
      }
    val bindingFuture = Http().newServerAt("localhost", 9001).bind(route)

  }

我的sbt-file如下所示:

libraryDependencies += ("com.typesafe.akka" %% "akka-http" % "10.2.9").cross(CrossVersion.for3Use2_13)

libraryDependencies += "com.typesafe.akka" %% "akka-actor-typed" % "2.6.19"

libraryDependencies += "com.typesafe.akka" %% "akka-stream" % "2.6.19"

libraryDependencies += "org.scalactic" %% "scalactic" % "3.2.11"

libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.12-RC1" % "test"

libraryDependencies += "org.scala-lang.modules" %% "scala-swing" % "3.0.0"

libraryDependencies += "com.google.inject" % "guice" % "4.2.3"

libraryDependencies += ("net.codingwell" %% "scala-guice" % "5.0.2").cross(CrossVersion.for3Use2_13)

libraryDependencies += "com.typesafe.play" %% "play-json" % "2.10.0-RC5"

libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % "2.0.1"

resolvers += Resolver.url("scoverage-bintray", url("https://dl.bintray.com/sksamuel/sbt-plugins/"))(Resolver.ivyStylePatterns)

这些是项目中的库

sbt: com.typesafe.akka:akka-actor-typed_3:2.6.19:jar
sbt: com.typesafe.akka:akka-actor_3:2.6.19:jar
sbt: com.typesafe.akka:akka-http-core_2.13:10.2.9:jar
sbt: com.typesafe.akka:akka-http_2.13:10.2.9:jar
sbt: com.typesafe.akka:akka-parsing_2.13:10.2.9:jar
sbt: com.typesafe.akka:akka-protobuf-v3_3:2.6.19:jar
sbt: com.typesafe.akka:akka-slf4j_3:2.6.19:jar
sbt: com.typesafe.akka:akka-stream_3:2.6.19:jar

当尝试执行上述代码时,将引发以下异常:

Exception in thread "main" java.lang.NoSuchMethodError: 'void akka.actor.ExtensionId.$init$(akka.actor.ExtensionId)'
    at akka.http.scaladsl.Http$.<clinit>(Http.scala:845)
    at caro.aview.ViewAPI$.run(ViewAPI.scala:23)
    at caro.aview.run.main(ViewAPI.scala:14)

有人知道为什么吗?任何帮助都将不胜感激,谢谢!

nvbavucw

nvbavucw1#

我也遇到了这个问题。解决方案是使用CrossVersion.for3Use2_13选项将所有akka库移回Scala 2.13,与您在akka-http中使用的选项相同。看起来像是scala 3版本的akka中的一个bug。

相关问题