使用spray-aws在spray框架下连接DynamoDB出错



我正在使用scala + akka + spray编写一个新的服务器,我需要连接到AWS中的DynamoDB。我做了一些研究,找到了你的"喷雾剂"。但是当我尝试使用它时,我得到了一些错误…Scala版本2.11.2,SBT版本应为0.13.1

$ sbt
> re-start
[info] Compiling 6 Scala sources to /home/ubuntu/dc-judi-server-scala/target/scala-2.11/classes...
[error] /home/ubuntu/dc-judi-server-scala/src/main/scala/com/example/Boot.scala:13: object dynamodb is not a member of package com.sclasen.spray.aws
[error] import com.sclasen.spray.aws.dynamodb
[error]        ^
[error] /home/ubuntu/dc-judi-server-scala/src/main/scala/com/example/Boot.scala:27: not found: value DynamoDBClientProps
[error]   val props = DynamoDBClientProps("xxx", "yyy", Timeout(100 seconds), dbsystem, dbsystem)
[error]               ^
[error] /home/ubuntu/dc-judi-server-scala/src/main/scala/com/example/Boot.scala:28: not found: type DynamoDBClient
[error]   val client = new DynamoDBClient(props)
[error]                    ^
[error] three errors found
[error] (compile:compile) Compilation failed
[error] Total time: 25 s, completed Aug 21, 2014 4:30:42 AM

附件是我的构建。sbt和Boot.scala我对这个框架很陌生,没有太多的经验。你能帮助我,给我一些见解吗?多谢。

organization  := "com.example"
version       := "0.1"
scalaVersion  := "2.11.2"
scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "utf8")
libraryDependencies ++= {
  val akkaV = "2.3.5"
  val sprayV = "1.3.1"
  Seq(
    "io.spray"            %%  "spray-can"     % sprayV,
    "io.spray"            %%  "spray-routing" % sprayV,
    "io.spray"            %%  "spray-testkit" % sprayV  % "test",
    "com.typesafe.akka"   %%  "akka-actor"    % akkaV,
    "com.typesafe.akka"   %%  "akka-slf4j"    % akkaV,
    "com.typesafe.slick"  %%  "slick"         % "2.1.0",
    "com.typesafe.akka"   %%  "akka-testkit"  % akkaV   % "test",
    "org.specs2"          %%  "specs2-core"   % "2.3.11" % "test",
    "mysql"               %   "mysql-connector-java" % "5.1.32",
    "ch.qos.logback"      %   "logback-classic" % "1.1.1",
    "com.sclasen"         %   "spray-aws_2.11"  % "0.3.4"
  )
}
resolvers ++= Seq(
    "Spray repository" at "http://repo.spray.io",
    "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
)
Revolver.settings
organization  := "com.example"
version       := "0.1"
scalaVersion  := "2.11.2"
scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "utf8")
libraryDependencies ++= {
  val akkaV = "2.3.5"
  val sprayV = "1.3.1"
  Seq(
    "io.spray"            %%  "spray-can"     % sprayV,
    "io.spray"            %%  "spray-routing" % sprayV,
    "io.spray"            %%  "spray-testkit" % sprayV  % "test",
    "com.typesafe.akka"   %%  "akka-actor"    % akkaV,
    "com.typesafe.akka"   %%  "akka-slf4j"    % akkaV,
    "com.typesafe.slick"  %%  "slick"         % "2.1.0",
    "com.typesafe.akka"   %%  "akka-testkit"  % akkaV   % "test",
    "org.specs2"          %%  "specs2-core"   % "2.3.11" % "test",
    "mysql"               %   "mysql-connector-java" % "5.1.32",
    "ch.qos.logback"      %   "logback-classic" % "1.1.1",
    "com.sclasen"         %   "spray-aws_2.11"  % "0.3.4"
  )
}
resolvers ++= Seq(
    "Spray repository" at "http://repo.spray.io",
    "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
)
Revolver.settings
com . example

import akka.actor.{ActorSystem, Props}
import akka.io.IO
import spray.can.Http
import akka.pattern.ask
import akka.util.Timeout
import scala.concurrent.duration._
import com.example.config.Configuration
import com.example.service._

import com.sclasen.spray.aws.dynamodb
import concurrent.Await
import concurrent.duration._
import com.amazonaws.services.dynamodbv2.model.ListTablesRequest
object Boot extends App with Configuration {
  // we need an ActorSystem to host our application in
  implicit val system = ActorSystem("on-spray-can")
  // A new actor system for host DB
  import com.sclasen.spray.aws._
  val dbsystem = ActorSystem("test")
  val props = DynamoDBClientProps("xxx", "yyy", Timeout(100 seconds), dbsystem, dbsystem)
  val client = new DynamoDBClient(props)
  try {
    val result = Await.result(client.sendListTables(new ListTablesRequest()), 100 seconds)
    println(result)
    result.getTableNames.size() should be >= 1
  } catch {
    case e: Exception =>
      println(e)
      e.printStackTrace()
  }
  // create and start our service actor
  val service = system.actorOf(Props[CustomerServiceActor], "demo-service")
  implicit val timeout = Timeout(5.seconds)
  // start a new HTTP server on port 80 with our service actor as the handler
  IO(Http) ? Http.Bind(service, host, port)
}

更新:我尝试将导入更改为:import com.sclasen.spray.aws._

但是DynamoDBClientProps和DynamoDBClient仍然找不到

在构建。然后,改成:

"com.sclasen"         % "spray-dynamodb" % "0.3.4" 

和Boot。Scala,直接导入这2:

import com.sclasen.spray.aws.dynamodb.DynamoDBClient
import com.sclasen.spray.aws.dynamodb.DynamoDBClientProps

最新更新