我是Scala的新手。在尝试用akka喷涂时,我收到以下错误
Error:(17, 17) type mismatch;
found : String("Welcome to Scala")
required: spray.httpx.marshalling.ToResponseMarshallable
complete("Welcome to Scala")
代码:
import spray.routing._
import akka.actor._
object SampleApplication extends App with SimpleRoutingApp {
implicit val actorSystem = ActorSystem()
startServer(interface = "localhost", port = 8080) {
get {
path("hello") {
complete {
"Welcome to Scala"
}
}
}
}
}
Maven依赖:
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>org.specs</groupId>
<artifactId>specs</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.spray</groupId>
<artifactId>spray-routing</artifactId>
<version>${spray.version}</version>
</dependency>
<dependency>
<groupId>io.spray</groupId>
<artifactId>spray-can</artifactId>
<version>${spray.version}</version>
</dependency>
<dependency>
<groupId>io.spray</groupId>
<artifactId>spray-httpx</artifactId>
<version>${spray.version}</version>
</dependency>
<dependency>
<groupId>io.spray</groupId>
<artifactId>spray-client</artifactId>
<version>${spray.version}</version>
</dependency>
<dependency>
<groupId>io.spray</groupId>
<artifactId>spray-json_2.11</artifactId>
<version>${spray.version}</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.11</artifactId>
<version>${akka.version}</version>
</dependency>
</dependencies>
Ide使用的是intellij Idea 14
依赖关系是否严格绑定到scala版本?
请帮助解决问题。
答案 0 :(得分:0)
你的例子适合我。我怀疑你的依赖项有些问题导致spray.httpx.marshalling
无法找到。
总的来说,我强烈建议不要将Scven与Scala一起使用,而是坚持使用SBT。使用SBT,您可以访问相同的依赖项(就像在Maven中一样),但也可以直接从GitHub指定依赖项。您还将获得增量编译。能够在sbt中启动shell或servlet容器也很方便。如果使用Intellij IDEA,它可以将SBT配置作为项目打开。它带有您可能需要的make任务(测试,运行,doc,发布本地,控制台)。