我正在编写一个使用scala + akka + spray的新服务器,我需要连接到AWS中的DynamoDB。我做了一些研究,找到了你的lib' spray-aws'。但是当我尝试使用它时,我得到了一些错误.. 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
附件是我的build.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
package 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 ......
答案 0 :(得分:0)
在build.sbt中,更改为:
"com.sclasen" % "spray-dynamodb" % "0.3.4"
并在Boot.scala中直接导入这个2:
import com.sclasen.spray.aws.dynamodb.DynamoDBClient
import com.sclasen.spray.aws.dynamodb.DynamoDBClientProps