【问题标题】:Scala 2.11.4, akka 2.3.7, spray 1.3.1 giving type mismatch errorScala 2.11.4、akka 2.3.7、spray 1.3.1 给出类型不匹配错误
【发布时间】:2014-12-16 17:56:19
【问题描述】:

我是 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 版本?

请帮忙解决问题。

【问题讨论】:

  • 您的示例运行良好 - 您如何运行它? ide, sbt ....?
  • 使用 maven 和 Intellij IDEA
  • 谁能帮助您提供您提供的信息? - 你应该在你的问题中提供这个 - 包括你的 maven 配置 - 或者更好:在 github 或 bitbucket 的项目链接...
  • 对不起。请检查。我已经更新了问题

标签: scala akka spray


【解决方案1】:

你的例子对我有用。我怀疑您的依赖项有问题,导致找不到 spray.httpx.marshalling

总的来说,我强烈建议不要将 Maven 与 Scala 一起使用,而是坚持使用 SBT。使用 SBT,您可以访问相同的依赖项(就像在 Maven 中一样),但也可以直接从 GitHub 指定依赖项。您还将获得增量编译。在 sbt 中启动 shell 或 servlet 容器的能力也很方便。如果您使用 Intellij IDEA,它可以将 SBT 配置作为项目打开。它还附带了您可能需要的 make 任务(测试、运行、文档、本地发布、控制台)。

【讨论】:

  • 你能分享一下为什么 sbt 比 maven 更受欢迎吗?
猜你喜欢
  • 1970-01-01
  • 2021-05-13
  • 1970-01-01
  • 2012-02-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-05
相关资源
最近更新 更多