akka http编译错误

mah*_*454 8 scala akka akka-http

我是akka框架的新手,现在尝试用这个框架设置简单的webservice.
写一个简单的akka​​-http应用程序:

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer

import scala.io.StdIn

object MainRunner extends App {

  implicit val system = ActorSystem("mySystem")
  implicit val materializer = ActorMaterializer
  implicit val ec = system.dispatcher

  val route =
    path("hello") {
      get {
        complete("Congratulation , this is your response")
      }
    }

  val bindingFuture = Http().bindAndHandle(route, "localhost", 8080)

  println(s"Server online at http://localhost:8080/\nPress RETURN to stop...")
  StdIn.readLine() // let it run until user presses return
  bindingFuture
    .flatMap(_.unbind()) // trigger unbinding from the port
    .onComplete(_ => system.terminate()) // and shutdown when done
}
Run Code Online (Sandbox Code Playgroud)

在编译时收到此错误:

Error:(34, 44) type mismatch;
 found   : akka.http.scaladsl.server.Route
    (which expands to)  akka.http.scaladsl.server.RequestContext => scala.concurrent.Future[akka.http.scaladsl.server.RouteResult]
 required: akka.stream.scaladsl.Flow[akka.http.scaladsl.model.HttpRequest,akka.http.scaladsl.model.HttpResponse,Any]
  val bindingFuture = Http().bindAndHandle(route, "localhost", 8080)
Run Code Online (Sandbox Code Playgroud)

怎么解决这个问题?

Ste*_*tti 18

在实例化你的时候,这只是一个简单的错误ActorMaterializer:

implicit val materializer = ActorMaterializer
Run Code Online (Sandbox Code Playgroud)

应该被替换

implicit val materializer = ActorMaterializer()
Run Code Online (Sandbox Code Playgroud)

随着范围的有效materializer,之间的隐式转换RouteFlow[HttpRequest, HttpResponse, _]预期应该发生,而编译器应该是快乐的.