首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法访问值akka.http.javadsl.unmarshalling中的类型解组程序

无法访问值akka.http.javadsl.unmarshalling中的类型解组程序
EN

Stack Overflow用户
提问于 2016-08-05 14:01:01
回答 1查看 434关注 0票数 1

我正在尝试使用Akka Http客户端API编写一个简单的Http客户端。为此,我编写了以下代码

代码语言:javascript
复制
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.http.scaladsl.unmarshalling._
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.{Sink, Source}
import scala.concurrent.duration._
import scala.concurrent.{Await}
import akka.http.scaladsl.server.Directives
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import spray.json._

final case class Post(postId: Int, id: Int, name: String, email: String, body: String)

trait JsonSupport extends SprayJsonSupport with DefaultJsonProtocol {
   implicit val postFormat = jsonFormat5(Post.apply)
}

class AkkaHttpClient extends App with Directives with JsonSupport {
   implicit val system = ActorSystem("my-Actor")
   implicit val actorMaterializer = ActorMaterializer()
   implicit val executionContext = system.dispatcher
   val httpClient = Http().outgoingConnection(host="http://jsonplaceholder.typicode.com/")
   val flow = Source.single(HttpRequest(uri = Uri("/comments/1")))
      .via(httpClient)
      .mapAsync(1)(r => Unmarshal(r.entity).to[Post])
      .runWith(Sink.head)

   val results = Await.result(flow, 15 seconds)
   println(results)
}

我的build.sbt文件如下所示

代码语言:javascript
复制
name := "Akka-Http-Client"
version := "1.0"
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
   "com.typesafe.akka" %% "akka-http-experimental" % "2.4.9-RC1",
   "com.typesafe.akka" %% "akka-http-spray-json-experimental" % "2.4.9-RC1"
)

当我试图编译我的代码时,我得到了这些错误

代码语言:javascript
复制
Error:scalac: missing or invalid dependency detected while loading class file 'Unmarshaller.class'.
Could not access type Unmarshaller in value akka.http.javadsl.unmarshalling,
because it (or its dependencies) are missing. Check your build definition for
missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
A full rebuild may help if 'Unmarshaller.class' was compiled against an incompatible version of akka.http.javadsl.unmarshalling.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-05 16:51:32

我在2.4.9-RC1上遇到了同样的问题,回退到2.4.8解决了这个问题。

或者,您可以使用此处描述的解决方法:https://github.com/akka/akka/issues/21105

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38782125

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档