更正错误: - 必需:spray.httpx.marshalling.ToResponseMarshallable

时间:2014-09-10 20:25:21

标签: scala spray

我是Scala的新手,并尝试编写一些REST API。我使用的是Scala 11.2,Spray 1.3.1和akka 2.3.6。

我基本上是想从喷雾中编译一个例子。 我得到的每条路线的错误是: 类型不匹配; found:String(" pong !!!!!!!!")必需:spray.httpx.marshalling.ToResponseMarshallable

我不确定它是否是版本不兼容问题,或者我缺少参考。

以下是我从喷涂示例中获取的路线定义:

package com.Shenandoah.SBIR.httpInterface


    import spray.routing.HttpService

    trait HttpInterface extends HttpService {  


      def pingRoute = path("ping") {
        get { complete("pong!!!!!!!!") }
      }

      def pongRoute = path("pong") {
        get { complete("pong!?") }
      }

        def pipRoute = path("pip") {
        get { complete("moonshine") }
      }

      def rootRoute = pingRoute ~ pongRoute ~ pipRoute
    }

    Here is the actor:

    package com.Shenandoah.SBIR.httpInterface

    import akka.actor._

    class HttpInterfaceActor extends HttpInterface with Actor {
      // the HttpService trait defines
      // only one abstract member, which connects the services environment
      // to the enclosing actor or test.
      def actorRefFactory = context


      def receive = runRoute(rootRoute)

}

2 个答案:

答案 0 :(得分:3)

您可能正在使用Scala 2.10的依赖项"io.spray" % "spray-routing" % "2.3.6"。有一个没有Scala版本标识的Spray版本,它是针对Scala 2.10编译的。这很不幸。

使用"io.spray" %% "spray-routing" % "2.3.6"(注意双%)来提取与Scala版本匹配的依赖项。这适用于Scala 2.10和2.11。

答案 1 :(得分:0)

看起来你错过了默认的marshallers。尝试添加到您的导入:

import spray.httpx.marshalling.Marshaller
相关问题