java.lang.nosuchmethoderror:' voidakka.actor.extensionId。$ init $(akka.actor.extensionid)'
我只是尝试使用Akka在Scala项目中实现一个少量的示例休息端点。 该代码看起来如下
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文件的外观如下:
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)
是否有人知道为什么是?任何帮助将不胜感激,谢谢!
I am simply trying to implement a little sample REST endpoint in a scala project using akka.
The code looks as follows
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)
}
My sbt-file looks as follows:
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)
And these are the libraries in the project
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
When trying to execute the above code, the following exception is thrown:
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)
Does anybody have an idea why that is? Any help would be appreciated, thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也有这个问题。该解决方案是使用Crossversion将所有Akka库返回到Scala 2.13.for3use2_13选项,与您用于Akka-HTTP相同的选项。对于Scala 3版本的AKKA中,看起来像是一个错误。
I also have this problem. The solution was moving all akka libraries back to Scala 2.13 using the CrossVersion.for3Use2_13 option, the same you have used for akka-http. Looks like a bug in akka for scala 3 version.
在我的项目中,我遇到了同样的错误。我在一个AKKA软件包中使用了2.13 Scala版本,在pom.xml中使用了另一个AKKA软件包的Scala版本。更改为使用3,并修复了错误。
In my project I was getting the same error. I was using 2.13 scala version for one akka package and 3 scala version for another akka package in the pom.xml. Changed both to use 3 and it fixed the error.