加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – 找不到隐含的……:akka.http.server.RoutingSetup

发布时间:2020-12-16 18:58:55 所属栏目:安全 来源:网络整理
导读:在玩akka-http实验1.0-M2时,我试图创建一个简单的Hello world示例. import akka.actor.ActorSystemimport akka.http.Httpimport akka.http.model.HttpResponseimport akka.http.server.Routeimport akka.stream.FlowMaterializerimport akka.http.server.Dir
在玩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找到不完全但相关的答案

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读