val behavior: Behavior[Message] = Behaviors.setup {
actorContext ⇒
logger.info("starting...")
implicit val actorSystem = actorContext.system.asInstanceOf[ActorSystem]
implicit val materializer = ActorMaterializer()(actorContext.asInstanceOf[ActorContext])
implicit val executionContext = actorContext.executionContext
val route =
path("hello") {
get {
complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, "<h1>Say hello to akka-http</h1>"))
}
}
val bindingFuture = Http().bindAndHandle(route, "localhost", 8888)
编译好了,但是当我运行我的代码时,我得到了
20:44:22.586 [Leaderboard-akka.actor.default-dispatcher-3] INFO net.kolotyluk.leaderboard.service.REST$ - starting...
[ERROR] [04/02/2018 20:44:22.592] [Leaderboard-akka.actor.default-dispatcher-2] [akka://Leaderboard/user/Http]
akka.actor.typed.internal.adapter.ActorSystemAdapter cannot be cast to akka.actor.ActorSystem
akka.actor.ActorInitializationException: akka://Leaderboard/user/Http: exception during creation
这有一些简单的解决方案吗?我怎样才能给Http()
一个ActorSystem所需要的东西?
Akka Typed似乎与其他Akka图书馆一起玩得不好
答案 0 :(得分:4)
您的代码似乎是将类型化的ActorSystem转换为无类型的ActorSystem,因此出错。而是使用适配器:
import akka.actor.typed.scaladsl.adapter._
val bindingFuture = Http(actorContext.system.toUntyped).bindAndHandle(route, "localhost", 8888)
以下是测试类似内容的示例: