我正面临一个奇怪的例外
java.lang.ClassCastException: Cannot cast akka.actor.Status$Success$ to akka.actor.Status$Success
at java.lang.Class.cast(Class.java:3094) ~[na:1.7.0_45]
at scala.concurrent.Future$$anonfun$mapTo$1.apply(Future.scala:405) ~[scala-library.jar:na]
at scala.util.Success$$anonfun$map$1.apply(Try.scala:206) ~[scala-library.jar:na]
at scala.util.Try$.apply(Try.scala:161) ~[scala-library.jar:na]
at scala.util.Success.map(Try.scala:206) ~[scala-library.jar:na]
问题是尾随$ - 类似于内部类......或者......
我的代码如下:
post {
authenticate(BasicAuth(pifUserPasswordAuthenticator _, realm = "bd pif import api")) {
user =>
entity(as[Array[Byte]]) { e =>
val resp = pifImportService.ask(PifTransactions("storeId","dob",e)).mapTo[akka.actor.Status.Success]
complete {
resp
}
}
}
}
因为我的演员回答如下:
Try(kafkaProducer.send(payload)) match {
case Success(_) =>
log.debug(s"$storeId - $dob - sending payload sucessfully sended to kafka")
sender() ! akka.actor.Status.Success
case Failure(throwable) =>
log.debug(s"$storeId - $dob - sending payload attempt failed $throwable")
sender() ! akka.actor.Status.Failure(throwable)
}
我错过任何诡计,还是我在这里使用了错误的名字?
THX
答案 0 :(得分:1)
sender() ! akka.actor.Status.Success
akka.actor.status.Success
是一个需要一个参数的案例类。看起来您没有使用类实例回复,但使用部分应用的Success.apply(_)函数,我相信这不是您计划做的,我相信:
case Success(_) =>
sender() ! akka.actor.Status.Success(storeId)