将play-json升级到2.7.0后,我开始遇到运行时错误:
[info] com.mycompany.controllers.HealthControllerSpec *** ABORTED ***
[info] java.lang.NoSuchMethodError: play.api.libs.json.JsonConfiguration$.apply$default$2()Lplay/api/libs/json/OptionHandlers;
[info] at com.mycompany.util.json.SnakeCase.$init$(SnakeCase.scala:41)
[info] at com.mycompany.util.playframework.controllers.HealthView$.<init>(HealthView.scala:15)
[info] at com.mycompany.util.playframework.controllers.HealthView$.<clinit>(HealthView.scala)
[info] at com.mycompany.util.playframework.controllers.HealthController.<init>(HealthController.scala:25)
[info] at com.mycompany.util.playframework.controllers.HealthControllerSpec.$anonfun$new$2(HealthControllerSpec.scala:30)
[info] at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85)
[info] at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:83)
[info] at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
[info] at org.scalatest.Transformer.apply(Transformer.scala:22)
[info] at org.scalatest.Transformer.apply(Transformer.scala:20)
谁能指出我的道理?
HealthView
:
case class HealthView(app: String, description: String, version: Option[String])
object HealthView extends SnakeCase {
def apply(config: Configuration): HealthView =
HealthView(
config.get[String]("app.name"),
config.get[String]("app.description"),
config.getOptional[String]("app.version")
)
implicit val format: OFormat[HealthView] = Json.format[HealthView]
}
SnakeCase
:
trait SnakeCase {
implicit val jsonConfig: Aux[Json.MacroOptions] = JsonConfiguration(SnakeCaseNaming)
}
次要版本的发行版应与二进制兼容。
正如Travis Brown指出的那样,您存在版本冲突。
由于在Play项目中play-json
包含,因此您不应再依赖play-json
。
如果有的话(因为我有一个多模块项目),请确保主要版本合适。
例如在plugins.sbt
:
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.7.0")
并作为依赖项(不在play模块中!):
"com.typesafe.play" %% "play-json" % "2.7.1"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句