喷涂依赖性错误

时间:2013-10-31 13:07:18

标签: scala intellij-idea akka scala-2.10 spray

我正在尝试在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 documentation我读到,更多IO被标记为来自akka 2.2.0的“实验性”

我要发疯了

1 个答案:

答案 0 :(得分: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>
        }
      }
    }
  }
}

您还应该确保build.sbt选择了Dependencies.scala中的任何内容。尝试删除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")