Akka HTTP 模糊隐式转换
Akka HTTP ambiguous implicit conversion
我正在通过这个 example 学习 Akka HTTP。为了学习,我把它转成了一个Maven项目。但是,使用 Akka v2.3.12 和 Akka Stream v1.0 时出现如下编译错误。 POST DSL 失败并出现类似的错误,为简洁起见我没有发布这些错误。我怎样才能得到 运行 的例子?
pathPrefix("ip") {
(get & path(Segment)) { ip =>
complete {
fetchIpInfo(ip).map[ToResponseMarshallable] {
case Right(ipInfo) => ipInfo
case Left(errorMessage) => BadRequest -> errorMessage
}
}
}
[ERROR] found : akka.http.scaladsl.server.Directive[(String,)]
[ERROR] required: ?{def apply: ?}
[ERROR] Note that implicit conversions are not applicable because they are ambiguous:
[ERROR] both method addDirectiveApply in object Directive of type [L](directive: akka.http.scaladsl.server.Directive[L])(implicit hac: akka.http.scaladsl.server.util.ApplyConverter[L])hac.In => akka.http.scaladsl.server.Route
[ERROR] and method fromDirective in object ConjunctionMagnet of type [L, R](other: akka.http.scaladsl.server.Directive[R])(implicit join: akka.http.scaladsl.server.util.TupleOps.Join[L,R])akka.http.scaladsl.server.ConjunctionMagnet[L]{type Out = akka.http.scaladsl.server.Directive[join.Out]}
[ERROR] are possible conversion functions from akka.http.scaladsl.server.Directive[(String,)] to ?{def apply: ?}
[ERROR] (get & path(Segment)) { ip =>
error: akka.http.scaladsl.server.Directive[(String,)] does not take parameters
[ERROR] (get & path(Segment)) { ip =>
事实证明这是由于 Spray(以及 akka-http)使用的深 implicit
链,因此正确导入至关重要。很少有示例显示导入和那些使用旧库的示例。
我正在通过这个 example 学习 Akka HTTP。为了学习,我把它转成了一个Maven项目。但是,使用 Akka v2.3.12 和 Akka Stream v1.0 时出现如下编译错误。 POST DSL 失败并出现类似的错误,为简洁起见我没有发布这些错误。我怎样才能得到 运行 的例子?
pathPrefix("ip") {
(get & path(Segment)) { ip =>
complete {
fetchIpInfo(ip).map[ToResponseMarshallable] {
case Right(ipInfo) => ipInfo
case Left(errorMessage) => BadRequest -> errorMessage
}
}
}
[ERROR] found : akka.http.scaladsl.server.Directive[(String,)]
[ERROR] required: ?{def apply: ?}
[ERROR] Note that implicit conversions are not applicable because they are ambiguous:
[ERROR] both method addDirectiveApply in object Directive of type [L](directive: akka.http.scaladsl.server.Directive[L])(implicit hac: akka.http.scaladsl.server.util.ApplyConverter[L])hac.In => akka.http.scaladsl.server.Route
[ERROR] and method fromDirective in object ConjunctionMagnet of type [L, R](other: akka.http.scaladsl.server.Directive[R])(implicit join: akka.http.scaladsl.server.util.TupleOps.Join[L,R])akka.http.scaladsl.server.ConjunctionMagnet[L]{type Out = akka.http.scaladsl.server.Directive[join.Out]}
[ERROR] are possible conversion functions from akka.http.scaladsl.server.Directive[(String,)] to ?{def apply: ?}
[ERROR] (get & path(Segment)) { ip =>
error: akka.http.scaladsl.server.Directive[(String,)] does not take parameters
[ERROR] (get & path(Segment)) { ip =>
事实证明这是由于 Spray(以及 akka-http)使用的深 implicit
链,因此正确导入至关重要。很少有示例显示导入和那些使用旧库的示例。