2015-11-12 51 views
2

我知道已被問過,但我似乎無法找到答案。 這裏是我的代碼:akka-http錯誤:無法找到參數um的隱式值:akka.http.scaladsl.unmarshalling.FromRequestUnmarshaller

import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport 
import spray.json.DefaultJsonProtocol 

final case class Client(clientId:Int, clientName:String, platformIds:Int, host:String, password:String) 

object ClientJson extends DefaultJsonProtocol with SprayJsonSupport { 
    implicit val clientFormat = jsonFormat5(Client) 
} 

class HTTPListenerActor extends Actor with ImplicitMaterializer with RoadMap { 

implicit val conf = context.system.settings.config 
implicit val system = context.system 
implicit val ec = context.dispatcher 


Await.result(Http().bindAndHandle(roads, "interface", 8080), Duration.Inf) 

override def receive:Receive = Actor.emptyBehavior 
} 

trait RoadMap extends Directives { 

val roads: Route = path("client"/IntNumber) { id => 
    import ClientJson._ 
    post { 
     entity(as[Client]) { c => complete {c} } 
    } 
    } 
} 

此代碼生成錯誤

[ant:scalac] /Users/smalov/Workspace/api-service/src/main/scala/com/acheron/HTTPListenerActor.scala:51: error: could not find implicit value for parameter um: akka.http.scaladsl.unmarshalling.FromRequestUnmarshaller[com.acheron.Client] 
[ant:scalac]   entity(as[Client]) { c => 

現在對於這種錯誤最常見的原因是忘記導入編組隱含在靠近roads定義的範圍,但是,我沒有忘記這一點。另一個原因可能是我隱含FlowMaterializer範圍而不是ActorMaterializer,但ImplictMaterializer特性照顧這一點。

還有什麼我可能會失蹤?

我使用Scala的2.11.7,阿卡2.3.11,阿卡-HTTP 1.0,噴霧JSON 1.3.2

回答

2

看來我需要ActorMaterializer在範圍上RoadMap特質。所以,加入implicit val materializer: ActorMaterializer解決了編譯問題。

我希望這個錯誤是有點更具描述性的....

3

我也得到了同樣的錯誤,並將其導入

「akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._後解決「

可能,這將有助於

+0

注意,您需要導入'」 com.typesafe.akka」 %% 「阿卡-HTTP噴霧JSON」 % 「10.0.5」''爲SprayJsonSupport在範圍內。這就是說,它並沒有解決我的問題。 – Moebius

相關問題