播放-json 2.7.1: java.lang.NoSuchMethodError
Play-json 2.7.1: java.lang.NoSuchMethodError
将 play-json 升级到 2.7.0 后,我开始遇到运行时错误:
[info] com.mycompany.controllers.HealthControllerSpec *** ABORTED ***
[info] java.lang.NoSuchMethodError: play.api.libs.json.JsonConfiguration$.apply$default()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(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 Project 中有一个 play-json
包含,你不应该对 play-json
.
有另一个依赖
如果你有(因为我有一个多模块项目),请确保主要版本适合。
例如在 plugins.sbt
:
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.7.0")
并作为依赖项(不在播放模块中!):
"com.typesafe.play" %% "play-json" % "2.7.1"
将 play-json 升级到 2.7.0 后,我开始遇到运行时错误:
[info] com.mycompany.controllers.HealthControllerSpec *** ABORTED ***
[info] java.lang.NoSuchMethodError: play.api.libs.json.JsonConfiguration$.apply$default()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(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 Project 中有一个 play-json
包含,你不应该对 play-json
.
如果你有(因为我有一个多模块项目),请确保主要版本适合。
例如在 plugins.sbt
:
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.7.0")
并作为依赖项(不在播放模块中!):
"com.typesafe.play" %% "play-json" % "2.7.1"