0

スプレーのドキュメントで「最小限の例」を実行しようとしています: スプレー 1.2-RC2 > ルーティング

私は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]

特に、akka.io.TcpをHttp.scalaにインポートすると問題が発生すると思います。Akkaのドキュメントで、より多くの IO については、akka 2.2.0 から「実験的」とマークされていることを読みました。

私はおかしくなりそうだ

4

1 に答える 1

1

アクター クラス/オブジェクトの明示的なインポートを追加し、暗黙的なアクター システム 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 に答える