0

我正在尝试运行 Spray 文档中的“Minimal Example”: Spray 1.2-RC2 > Routing

我正在使用 scala 2.10.3,这是我在 Dependencies.scala 文件中描述的配置的一部分:

val sprayVersion = "1.2-RC2"
val sprayCan     = "io.spray"           %    "spray-can"     % sprayVersion
val sprayRouting = "io.spray"           %    "spray-routing" % sprayVersion
val sprayJson    = "io.spray"           %%   "spray-json"    % "1.2.5"

val akkaVersion  = "2.2.3"
val akkaActor    = "com.typesafe.akka"  %%  "akka-actor"     % akkaVersion
val akkaSlf4j    = "com.typesafe.akka"  %%  "akka-slf4j"     % akkaVersion
val akkaTestKit  = "com.typesafe.akka"  %%  "akka-testkit"   % akkaVersion

这是我的简单代码,如示例:

import spray.routing.SimpleRoutingApp

    object Main extends App with SimpleRoutingApp {
      startServer(interface = "localhost", port = 8080) {
        path("hello") {
          get {
            complete {
              <h1>Say hello to spray</h1>
            }
          }
        }
      }
    }

在编译时我收到以下错误

bad symbolic reference. A signature in Http.class refers to term actor
in package akka which is not available.
It may be completely missing from the current classpath, or the version on
the classpath might be incompatible with the version used when compiling Http.class.
  startServer(interface = "localhost", port = 8080) {
  ^

我只是不知道我在做什么错。

编辑:我认为错误是由方法的返回 startServer 中使用的 Http.Bound 引起的:

IO(Http).ask(Http.Bind(serviceActor, interface, port, backlog, options, settings)).mapTo[Http.Bound]

特别是我认为它在 Http.scala 中导入akka.io.Tcp会给带来问题。在Akka 文档中,我读到更多 IO 从 akka 2.2.0 被标记为“实验性”

我要疯了

4

1 回答 1

1

尝试添加actor类/对象的显式导入,并声明隐式actor系统val。像这样:

import spray.routing.SimpleRoutingApp
import akka.actor._

object Main extends App with SimpleRoutingApp {
  implicit val system = ActorSystem("my-system")

  startServer(interface = "localhost", port = 8080) {
    path("hello") {
      get {
        complete {
          <h1>Say hello to spray</h1>
        }
      }
    }
  }
}

您还应该确保 Dependencies.scala 中的任何内容都被 build.sbt 拾取。尝试删除 Dependencies.scala 文件并将依赖项添加到 build.sbt 中,如下所示,

name := """spray-rest"""

version := "1.0"

scalaVersion := "2.10.3"

resolvers += "spray repo" at "http://repo.spray.io"

resolvers += "spray nightlies" at "http://nightlies.spray.io"

libraryDependencies ++= Seq(
  "com.typesafe.akka"  %% "akka-actor"       % "2.2.3",
  "com.typesafe.akka"  %% "akka-slf4j"       % "2.2.3",
  "ch.qos.logback"      % "logback-classic"  % "1.0.13",
  "io.spray"            % "spray-can"        % "1.2-RC2",
  "io.spray"            % "spray-routing"    % "1.2-RC2",
  "io.spray"           %% "spray-json"       % "1.2.3",
  "org.specs2"         %% "specs2"           % "1.14"         % "test",
  "io.spray"            % "spray-testkit"    % "1.2-RC2" % "test",
  "com.typesafe.akka"  %% "akka-testkit"     % "2.2.3"        % "test",
  "com.novocode"        % "junit-interface"  % "0.7"          % "test->default"
)

scalacOptions ++= Seq(
  "-unchecked",
  "-deprecation",
  "-Xlint",
  "-Ywarn-dead-code",
  "-language:_",
  "-target:jvm-1.7",
  "-encoding", "UTF-8"
)

testOptions += Tests.Argument(TestFrameworks.JUnit, "-v")
于 2013-11-01T22:20:08.417 回答