Java Play 框架 - NoClassDefFoundError:播放/配置
Posted
技术标签:
【中文标题】Java Play 框架 - NoClassDefFoundError:播放/配置【英文标题】:Java Play Framework - NoClassDefFoundError: play/Configuration 【发布时间】:2019-02-22 09:19:02 【问题描述】:我刚刚开始使用 Java Play 框架并取得了一些进展,但现在我打算添加 JavaEbean OEM,我浏览了文档但仍然收到错误 NoClassDefFoundError: play/Configuration强>
应用程序.conf
# This is the main configuration file for the application.
# https://www.playframework.com/documentation/latest/ConfigFile
ebean.default = ["models.*"]
plugins.sbt
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.7.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "4.1.0")
我的模特:
import io.ebean.Model;
public class Book extends Model ..
build.sbt
name := """BookStoreApp"""
organization := "com.example"
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean)
scalaVersion := "2.12.8"
libraryDependencies += guice
我从 sbt 开始,做了更新一切都很好,但是如果我编译,我得到以下错误:
[error] java.lang.NoClassDefFoundError: play/Configuration
[error] at play.db.ebean.ModelsConfigLoader.apply(ModelsConfigLoader.java:27)
[error] at play.db.ebean.ModelsConfigLoader.apply(ModelsConfigLoader.java:21)
[error] at play.ebean.sbt.PlayEbean$.$anonfun$configuredEbeanModels$4(PlayEbean.scala:153)
[error] at play.ebean.sbt.PlayEbean$.withClassLoader$1(PlayEbean.scala:130)
[error] at play.ebean.sbt.PlayEbean$.$anonfun$configuredEbeanModels$1(PlayEbean.scala:150)
[error] at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error] at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:40)
[error] at sbt.std.Transform$$anon$4.work(System.scala:67)
[error] at sbt.Execute.$anonfun$submit$2(Execute.scala:269)
[error] at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error] at sbt.Execute.work(Execute.scala:278)
[error] at sbt.Execute.$anonfun$submit$1(Execute.scala:269)
[error] at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
[error] at sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
[error] at java.util.concurrent.FutureTask.run(Unknown Source)
[error] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
[error] at java.util.concurrent.FutureTask.run(Unknown Source)
[error] at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
[error] at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
[error] at java.lang.Thread.run(Unknown Source)
[error] Caused by: java.lang.ClassNotFoundException: play.Configuration
[error] at java.net.URLClassLoader.findClass(Unknown Source)
[error] at java.lang.ClassLoader.loadClass(Unknown Source)
[error] at java.lang.ClassLoader.loadClass(Unknown Source)
[error] at play.db.ebean.ModelsConfigLoader.apply(ModelsConfigLoader.java:27)
[error] at play.db.ebean.ModelsConfigLoader.apply(ModelsConfigLoader.java:21)
[error] at play.ebean.sbt.PlayEbean$.$anonfun$configuredEbeanModels$4(PlayEbean.scala:153)
[error] at play.ebean.sbt.PlayEbean$.withClassLoader$1(PlayEbean.scala:130)
[error] at play.ebean.sbt.PlayEbean$.$anonfun$configuredEbeanModels$1(PlayEbean.scala:150)
[error] at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error] at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:40)
[error] at sbt.std.Transform$$anon$4.work(System.scala:67)
[error] at sbt.Execute.$anonfun$submit$2(Execute.scala:269)
[error] at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error] at sbt.Execute.work(Execute.scala:278)
[error] at sbt.Execute.$anonfun$submit$1(Execute.scala:269)
[error] at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
[error] at sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
[error] at java.util.concurrent.FutureTask.run(Unknown Source)
[error] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
[error] at java.util.concurrent.FutureTask.run(Unknown Source)
[error] at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
[error] at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
[error] at java.lang.Thread.run(Unknown Source)
[error] (Compile / playEbeanModels) java.lang.NoClassDefFoundError: play/Configuration
[error] Total time: 7 s, completed 22.02.2019 10:07:26
如果我运行 sbt run 我得到与上面相同的错误,加上:
[error] a.a.ActorSystemImpl - Internal server error, sending 500 response
akka.http.impl.util.One2OneBidiFlow$OutputTruncationException: Inner flow was completed without producing result elements for 1 outstanding elements
at akka.http.impl.util.One2OneBidiFlow$OutputTruncationException$.apply(One2OneBidiFlow.scala:22)
at akka.http.impl.util.One2OneBidiFlow$OutputTruncationException$.apply(One2OneBidiFlow.scala:22)
at akka.http.impl.util.One2OneBidiFlow$One2OneBidi$$anon$1$$anon$4.onUpstreamFinish(One2OneBidiFlow.scala:97)
at akka.stream.impl.fusing.GraphInterpreter.processEvent(GraphInterpreter.scala:504)
at akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:378)
at akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:588)
at akka.stream.impl.fusing.GraphInterpreterShell$AsyncInput.execute(ActorGraphInterpreter.scala:472)
at akka.stream.impl.fusing.GraphInterpreterShell.processEvent(ActorGraphInterpreter.scala:563)
at akka.stream.impl.fusing.ActorGraphInterpreter.akka$stream$impl$fusing$ActorGraphInterpreter$$processEvent(ActorGraphInterpreter.scala:745)
at akka.stream.impl.fusing.ActorGraphInterpreter$$anonfun$receive$1.applyOrElse(ActorGraphInterpreter.scala:760)
[error] (Compile / playEbeanModels) java.lang.NoClassDefFoundError: play/Configuration
【问题讨论】:
您的conf/application.conf
中是否配置了数据库连接?
【参考方案1】:
您需要更改play
或ebean
版本。
play
更改了 2.7 中的默认 Configuration
类:https://www.playframework.com/documentation/2.7.x/JavaConfigMigration26。
ebean
插件版本和它对应于play
:
https://github.com/playframework/play-ebean#releases
那么接下来
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.7.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "4.1.0")
必须改为
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.21")
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "4.1.0")
或
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.7.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "5.0.0")
【讨论】:
正如我在 github 报告中看到的那样,2.7.0 版在使用 ebean 5.0.0 时有些不稳定。改玩版本 2.6.6 和 Ebean 4.6.1 确实解决了问题!谢谢 sbt-play-ebean v5.0.0 不可安装,所以 v5.0.1 可以与 play v2.7.0 在 Play 2.8.8 上我收到了类似的错误,但是当我删除ebean.default = ["models.*"]
后它就消失了以上是关于Java Play 框架 - NoClassDefFoundError:播放/配置的主要内容,如果未能解决你的问题,请参考以下文章