我是Scala的新手,正在尝试编写一些REST API。我使用的是Scala 11.2、Spray 1.3.1和akka 2.3.6。
我基本上是在试着从spray编译一个例子。我得到的每条路由的错误是:类型不匹配;找到:字符串(“pong!”)必需: spray.httpx.marshalling.ToResponseMarshallable
我不确定这是一个版本不兼容的问题,还是我遗漏了一个引用。
下面是我的路由定义,取自spray示例:
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)}
发布于 2014-09-23 22:39:51
您可能正在使用针对Scala2.10的依赖项"io.spray" % "spray-routing" % "2.3.6"。有一个Spray版本没有指定Scala版本,它是针对Scala 2.10编译的。这是不幸的。
使用"io.spray" %% "spray-routing" % "2.3.6" (注意双重%)来拉入与您的Scala版本匹配的依赖项。这将适用于Scala 2.10和2.11。
发布于 2014-09-11 04:48:31
看起来您缺少默认的封送处理程序。尝试添加到您的导入:
import spray.httpx.marshalling.Marshallerhttps://stackoverflow.com/questions/25774478
复制相似问题