Question

I'm trying to run the "Minimal Example" in the Spray documentation: Spray 1.2-RC2 > Routing

i'm using scala 2.10.3 and this is part of my configuration described in the file 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

And this is my simple code like the example:

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>
            }
          }
        }
      }
    }

At compile time I get the following error

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) {
  ^

I just can not figure out what am I doing wrong.

EDIT: I think the error is caused by Http.Bound used in the method's return startServer:

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

in particular I think it imports akka.io.Tcp in Http.scala to give you problems. On the Akka documentation i read that for more IO is marked as “experimental” from akka 2.2.0

I'm going crazy

Was it helpful?

Solution

Try add explicit import of actor classes/objects, and declare implicit actor system val. Like this:

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>
        }
      }
    }
  }
}

You should also need to make sure that whatever in Dependencies.scala is picked up by build.sbt. Try remove Dependencies.scala file and add the dependencies to build.sbt like this,

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")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top