4

我想将 spray.io 与 scala 2.11.x akka 2.3.x 一起使用,我在 spray.io 的项目信息页面中找到以下内容:

spray 1.3.1 is built against Scala 2.10.3 and Akka 2.3.0 as well as Scala 2.11.1 and Akka 2.3.2.

当我使用 spray-client 时,我遇到了一些问题,然后我在 spray.io 的文档页面中发现,spray-client 依赖于 akka 2.10.x:

akka-actor 2.2.x (with ‘provided’ scope, i.e. you need to pull it in yourself)

提供的范围是什么意思?如何将它与用 scala 2.11.x akka 2.3.x 编写的程序的其他部分一起使用?

编辑

以下是文档页面中列出的最简单的用例:

import akka.actor.ActorSystem
import scala.concurrent.Future
object main {
  def main(args: Array[String]) {
    import spray.http._
    import spray.client.pipelining._
    implicit val system = ActorSystem()
    import system.dispatcher // execution context for futures
    val pipeline: HttpRequest => Future[HttpResponse] = sendReceive
    val response: Future[HttpResponse] = pipeline(Get("http://spray.io/"))
  }
}

使用 build.sbt:

scalaVersion := "2.11.1"
libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.3.2"
libraryDependencies += "io.spray" % "spray-client" % "1.3.1"

虽然这编译得很好,但它遇到了运行时错误:

Uncaught error from thread [default-akka.actor.default-dispatcher-2] shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled for ActorSystem[default]
java.lang.NoClassDefFoundError: scala/runtime/AbstractPartialFunction$mcVL$sp
  at ...
4

1 回答 1

5

提供的依赖意味着,spray 需要该依赖,但希望开发人员在其构建配置中提供它。因此,您需要在构建配置中添加 akka-actor。

如果您使用的是 sbt,则可以将以下行添加到您的依赖项中。

    "com.typesafe.akka"     %% "akka-actor"         % 2.3.2,
于 2014-09-09T13:17:58.440 回答