将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)
}
发行版的次要版本应与二进制兼容。
答案 0 :(得分:3)
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"