2014-09-10 81 views
1

我是新來的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) 

}

回答

0

看起來你缺少默認marshallers。嘗試添加到您的進口:

import spray.httpx.marshalling.Marshaller 
3

您可能正在使用的依賴"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。