我知道已经有人问过了,但我似乎找不到答案。这是我的代码:
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
trait 可以解决这个问题。
还有什么我可能会丢失的吗?
我正在使用 Scala 2.11.7、Akka 2.3.11、akka-http 1.0、spray-json 1.3.2