scala – 找不到隐含的……:akka.http.server.RoutingSetup
在玩akka-http实验1.0-M2时,我试图创建一个简单的Hello world示例.
import akka.actor.ActorSystem import akka.http.Http import akka.http.model.HttpResponse import akka.http.server.Route import akka.stream.FlowMaterializer import akka.http.server.Directives._ object Server extends App { val host = "127.0.0.1" val port = "8080" implicit val system = ActorSystem("my-testing-system") implicit val fm = FlowMaterializer() val serverBinding = Http(system).bind(interface = host,port = port) serverBinding.connections.foreach { connection ? println("Accepted new connection from: " + connection.remoteAddress) connection handleWith Route.handlerFlow { path("") { get { complete(HttpResponse(entity = "Hello world?")) } } } } } 编译失败,无法找到参数设置的隐式值:akka.http.server.RoutingSetup 另外,如果我改变了 complete(HttpResponse(entity = "Hello world?")) 同 complete("Hello world?") 我得到另一个错误:类型不匹配; found:String(“Hello world?”)必需:akka.http.marshalling.ToResponseMarshallable 解决方法
通过研究,我能够理解缺少执行上下文的问题.要解决这个问题,我需要包含这个:
implicit val executionContext = system.dispatcher 查看akka / http / marshalling / ToResponseMarshallable.scala我看到ToResponseMarshallable.apply需要它返回Future [HttpResponse]. 此外,在akka / http / server / RoutingSetup.scala中,RoutingSetup.apply需要它. 可能是akka团队只需要添加更多@implicitNotFounds.我能够在direct use of Futures in Akka和spray Marshaller for futures not in implicit scope after upgrading to spray 1.2找到不完全但相关的答案 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |