更正错误: - 必需:spray.httpx.marshalling.ToResponseMarshallable
问题描述:
我是新来的Scala,并试图写一点REST API。我正在使用Scala 11.2,Spray 1.3.1和akka 2.3.6。更正错误: - 必需:spray.httpx.marshalling.ToResponseMarshallable
我基本上试图从喷雾中编写一个例子。 我得到的每条路线的错误是: 类型不匹配;发现:String(“pong !!!!!!!!”)required: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)
}
答
看起来你缺少默认marshallers。尝试添加到您的进口:
import spray.httpx.marshalling.Marshaller
答
您可能正在使用的依赖"io.spray" % "spray-routing" % "2.3.6"
这是斯卡拉2.10。有一个没有Scala版本标识的Spray版本,它是针对Scala 2.10编译的。这很不幸。
使用"io.spray" %% "spray-routing" % "2.3.6"
(注意双%
)拉入与您的Scala版本匹配的依赖项。这将适用于Scala 2.10和2.11。