- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这两个错误:
Error:(39, 20) Cannot find an implicit ExecutionContext. You might pass
an (implicit ec: ExecutionContext) parameter to your method
or import scala.concurrent.ExecutionContext.Implicits.global.
val pipeline = sendReceive
^
Error:(39, 20) not enough arguments for method sendReceive: (implicit refFactory: akka.actor.ActorRefFactory, implicit executionContext: scala.concurrent.ExecutionContext, implicit futureTimeout: akka.util.Timeout)spray.client.pipelining.SendReceive.
Unspecified value parameter executionContext.
val pipeline = sendReceive
^
import scala.util.{Success, Failure}
import scala.concurrent.duration._
import akka.actor.ActorSystem
import akka.pattern.ask
import akka.event.Logging
import akka.io.IO
import spray.can.Http
import spray.client.pipelining._
import spray.util._
import argonaut._, Argonaut._
object test {
case class Elevation(location: Location, elevation: Double)
case class Location(lat: Double, lng: Double)
case class GoogleApiResult(status: String, results: List[Elevation])
implicit def locationFormat: CodecJson[Location] = casecodec2(Location.apply, Location.unapply)("lat", "lng")
implicit def elevationFormat: CodecJson[Elevation] = casecodec2(Elevation.apply, Elevation.unapply)("location", "elevation")
implicit def googleApiResultFormat: CodecJson[GoogleApiResult] = casecodec2(GoogleApiResult.apply, GoogleApiResult.unapply)("status", "results")
object Main extends App {
// we need an ActorSystem to host our application in
implicit val system = ActorSystem("simple-spray-client")
// execution context for futures below
val log = Logging(system, getClass)
log.info("Requesting the elevation of Mt. Everest from Googles Elevation API...")
val pipeline = sendReceive
val responseFuture= pipeline {
Get("http://maps.googleapis.com/maps/api/elevation/json?locations=27.988056,86.925278&sensor=false")
}
responseFuture.onComplete {
case Success(result) =>
println(result)
log.info("The elevation of Mt.Everest is: {} m", result.toString.decodeOption[Elevation].get)
shutdown()
case Failure(error) =>
log.error(error, "Couldn't get elevation")
shutdown()
}
def shutdown(): Unit = {
IO(Http).ask(Http.CloseAll)(1.second).await
system.shutdown()
}
}
}`
最佳答案
您需要import scala.concurrent.ExecutionContext.Implicits.global
作为错误指定。
你看sendReceive
方法有 implicit executionContext: scala.concurrent.ExecutionContext
参数。
--编辑--
这个答案得到了很多关注,所以我想更新它。如您所见,这是默认的全局执行上下文,声明如下;
/**
* The implicit global `ExecutionContext`. Import `global` when you want to provide the global
* `ExecutionContext` implicitly.
*
* The default `ExecutionContext` implementation is backed by a work-stealing thread pool. By default,
* the thread pool uses a target number of worker threads equal to the number of
* [[https://docs.oracle.com/javase/8/docs/api/java/lang/Runtime.html#availableProcessors-- available processors]].
*/
implicit lazy val global: ExecutionContextExecutor = impl.ExecutionContextImpl.fromExecutor(null: Executor)
关于scala - 找不到隐式 ExecutionContext。你可能会通过spray scala,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33304047/
使用 Spray-io 构建我的第一个 servlet 非常简单。 但是 header 中引用的资源从未找到。 ...... 必须将这些资源放在哪个目录中,或者如何引导喷雾在那里查找? 简单的问题,但
我想了解 Spray 中的指令是如何工作的。 As per the documentation : The general anatomy of a directive is as follows:
对于 POST 和 PUT 请求,我使用以下语法: put { entity(as[CaseClass]) { entity => returnsOption(entity).map(r
我正在使用 marathon-lb 运行 DC/OS 1.7。 spray.io 1.3.3 向所有 marathon-lb/HAProxy 健康检查调用返回 400:请求具有相对 URI 并且缺少主
我正在使用 marathon-lb 运行 DC/OS 1.7。 spray.io 1.3.3 向所有 marathon-lb/HAProxy 健康检查调用返回 400:请求具有相对 URI 并且缺少主
我在我的喷雾 jar 服务器中使用以下路径(使用喷雾 1.2): path("my"/"path"){ get{ complete{ val buf:Array[Byte] =
我正在尝试重现 this或 this ,但我不断收到一个我无法修复的错误... 首先,这是我的依赖项: compile 'io.spray:spray-can_2.11:1.3.1' compile
我正在用 Spray 编写一个自定义指令,用于管理任何用户请求的速率限制。 我要一个 LimitManager某个地方将处理每个请求的自定义限制和规则。这个唯一需要的信息LimitManager是 u
我的服务的所有 API 调用都是 HTTP POST,参数在多部分正文中传递。目前我的身份验证如下所示 formField("token".as[String]) { token => auth
喷雾真的很容易,但我在理解路由方面遇到了问题。这就像一只狗有时会取骨头,但通常不会。我错过了什么? 有没有办法查看Spray尝试了哪些路线,以及为什么放弃某些路线?这将基本上解决这个问题。 logRe
如何在Spray-json中正确反序列化嵌套对象? import spray.json._ case class Person(name: String) case class
来自spray.io文档页面: color extract value of parameter “color” as String color.? extract optional value of
我使用 spray 和 akka actor 构建了一个 scala 应用程序。 我的问题是请求是同步的,服务器不能同时管理很多请求。 这是正常行为吗?我该怎么做才能避免这种情况? 这是我的启动代码:
我正在尝试从 Spray 提供大型临时文件。 HTTP 请求完成后,我需要删除这些文件。到目前为止,我找不到这样做的方法...... 我使用的代码类似于 this或者这个: res
Spray-json 依赖于范围内隐式 JsonWriter[T] 的存在调用toJson时在 T 的实例上. 假设我有几个具体子类型的特征,每个子类型都有一个 JsonWriter: trait B
我正在尝试从喷雾路由中的完整指令返回一个列表。 complete { List("hello") } 但是,我收到一个错误 - Expression of type List[String] do
我正在使用喷雾路由来构建一个简单的 HTTP 服务器。该服务器调用许多需要一段时间才能响应(秒)的服务。当并发请求数变得很大时,我们想拒绝请求。否则,大量并发请求会使系统陷入困境,对任何人都不利。 有
我是Spray-Json API的新手,并且试图解析Docker REST API的Json响应。 There是使用Spray-Json解析此Google Map Json响应的一个干净示例: {
我正在使用 Spray-json 将自定义对象列表编码(marshal)到 JSON 中。我有以下案例类及其 JsonProtocol。 case class ElementResponse(name
MyService.scala:33: could not find implicit value for parameter eh: spray.routing.ExceptionHandler 我
我是一名优秀的程序员,十分优秀!