错误:java.lang.NoClassDefFoundError:akka / stream /在更新到2.5.2 Akka版本后融合$

时间:2017-05-28 20:38:02

标签: scala akka

我正在使用Akka开发一个小型微服务。包含在HttpServer中,如下所示:

object HttpServer extends App {

  val config = ConfigFactory.load()

  implicit val system = ActorSystem(config.getString("server.actor-system"))
  implicit val materializer = ActorMaterializer()

  // needed for the future flatMap/onComplete in the end
  implicit val executionContext = system.dispatcher

  implicit val logger = Logging(system, getClass)

  implicit val employeeRouterActor = system.actorOf(Props[EmployeeRouterActor], name = "employeeRouterActor")

  val employeeRoutes = new EmployeeRoutes()
  val routes = employeeRoutes.route // ~ otherRoutes.route

  val host = config.getString("server.host")
  val port = config.getInt("server.port")
  val bindingFuture = Http().bindAndHandle(routes, host, port)

  logger.info(s"Server online at http://$host:$port/\nPress RETURN to stop...")
  StdIn.readLine() // let it run until user presses return
  logger.info(s"Server stopped :(")
  bindingFuture
    .flatMap(_.unbind()) // trigger unbinding from the port
    .onComplete(_ => system.terminate()) // and shutdown when done

}

更新到最新的Akka版本后,从_2.12:2.4.17到_2.12:2.5.2我在服务器启动时总是出现以下错误:

objc[27272]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/bin/java (0x10983c4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10a8914e0). One of the two will be used. Which one is undefined.
22:29:35.457 [my-system-akka.actor.default-dispatcher-2] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
Exception in thread "main" java.lang.NoClassDefFoundError: akka/stream/Fusing$
    at akka.http.scaladsl.HttpExt.fuseServerFlow(Http.scala:87)
    at akka.http.scaladsl.HttpExt.bindAndHandle(Http.scala:181)
    at server.HttpServer$.delayedEndpoint$server$HttpServer$1(HttpServer.scala:36)
    at server.HttpServer$delayedInit$body.apply(HttpServer.scala:17)
    at scala.Function0.apply$mcV$sp(Function0.scala:34)
    at scala.Function0.apply$mcV$sp$(Function0.scala:34)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.App.$anonfun$main$1$adapted(App.scala:76)
    at scala.collection.immutable.List.foreach(List.scala:389)
    at scala.App.main(App.scala:76)
    at scala.App.main$(App.scala:74)
    at server.HttpServer$.main(HttpServer.scala:17)
    at server.HttpServer.main(HttpServer.scala)
Caused by: java.lang.ClassNotFoundException: akka.stream.Fusing$
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 13 more

服务器在2.4.17中运行良好。更新到2.5.2之后是否有人收到此错误?

1 个答案:

答案 0 :(得分:1)

解决方案是更新Akka Http,更新到最新版本,在本例中为10.0.7。