play.api.UnexpectedException:意外异常[NoClassDefFoundError:slick / backend / DatabaseConfig]

时间:2017-03-19 18:08:37

标签: scala playframework sbt slick

我要设置一个带有play框架的项目和带有slick-codegen的postgres。我的项目正在编译而没有错误并且生成的Tables类是正确的。但是当我运行该项目时,它会给我Sun Mar 19 2017 13:30:00 GMT+0530 (India Standard Time)。 这是完整的痕迹:

play.api.UnexpectedException: Unexpected exception[NoClassDefFoundError: slick/backend/DatabaseConfig]

我的项目分为2个子项目。 Play项目和用于生成Tables类的codegen项目。

我的build.sbt看起来像这样:

play.api.UnexpectedException: Unexpected exception[NoClassDefFoundError: slick/backend/DatabaseConfig]
    at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:184)
    at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:131)
    at scala.Option.map(Option.scala:146)
    at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:131)
    at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:129)
    at scala.util.Success.flatMap(Try.scala:231)
    at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:129)
    at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:121)
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
Caused by: java.lang.NoClassDefFoundError: slick/backend/DatabaseConfig
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.getDeclaredMethods(Class.java:1975)
    at com.google.inject.spi.InjectionPoint.getInjectionPoints(InjectionPoint.java:688)
    at com.google.inject.spi.InjectionPoint.forInstanceMethodsAndFields(InjectionPoint.java:380)
    at com.google.inject.internal.ConstructorBindingImpl.getInternalDependencies(ConstructorBindingImpl.java:165)
    at com.google.inject.internal.InjectorImpl.getInternalDependencies(InjectorImpl.java:616)
    at com.google.inject.internal.InjectorImpl.cleanup(InjectorImpl.java:572)
    at com.google.inject.internal.InjectorImpl.initializeJitBinding(InjectorImpl.java:558)
    at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:887)
Caused by: java.lang.ClassNotFoundException: slick.backend.DatabaseConfig
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.getDeclaredMethods(Class.java:1975)
    at com.google.inject.spi.InjectionPoint.getInjectionPoints(InjectionPoint.java:688)
    at com.google.inject.spi.InjectionPoint.forInstanceMethodsAndFields(InjectionPoint.java:380)
    at com.google.inject.internal.ConstructorBindingImpl.getInternalDependencies(ConstructorBindingImpl.java:165)
    at com.google.inject.internal.InjectorImpl.getInternalDependencies(InjectorImpl.java:616)

我也尝试删除所有使用数据库和Tables类的代码,但我仍然遇到此错误。

我使用自定义postgres驱动程序,它在codegen项目中但是我在根项目中添加了dependsOn(codegen),这应该不是问题。它也正在编译sbt compile没有问题。

编辑: 经过一些测试后,我将光滑的版本更改为import sbt.Keys._ val slickVersion = "3.2.0" scalaVersion := "2.11.8" // The Play project itself lazy val root = (project in file(".")) .settings( libraryDependencies ++= List( "com.netaporter" %% "scala-uri" % "0.4.14", "net.codingwell" %% "scala-guice" % "4.1.0", "com.typesafe.play" %% "play-slick" % "2.0.2", "com.typesafe.play" %% "play-slick-evolutions" % "2.0.2" ) ) .settings(sharedSettings) .enablePlugins(Common, PlayScala) .settings( name := """Play app""" ) .dependsOn(codegen) lazy val codegen = project .settings(sharedSettings) .settings( libraryDependencies ++= List( "com.typesafe.slick" %% "slick-codegen" % slickVersion ) ) lazy val sharedSettings = Seq( scalaVersion := "2.11.8", scalacOptions := Seq("-feature", "-unchecked", "-deprecation"), libraryDependencies ++= List( "com.typesafe.scala-logging" %% "scala-logging-slf4j" % "2.1.2", "org.slf4j" % "slf4j-api" % "1.7.23", "org.slf4j" % "log4j-over-slf4j" % "1.7.23", // for any java classes looking for this "ch.qos.logback" % "logback-classic" % "1.2.1", "com.typesafe.slick" %% "slick" % slickVersion, "org.postgresql" % "postgresql" % "9.4.1212", "com.github.tminglei" %% "slick-pg" % "0.15.0-RC", "com.github.tminglei" %% "slick-pg_play-json" % "0.15.0-RC", "com.github.tminglei" %% "slick-pg_joda-time" % "0.15.0-RC", "com.github.tminglei" %% "slick-pg_jts" % "0.15.0-RC", "joda-time" % "joda-time" % "2.9.7", "org.joda" % "joda-convert" % "1.8" ) ) 3.1.1版本为com.github.tminglei,现在它适用于我。

1 个答案:

答案 0 :(得分:1)

我有同样的classapth问题,最后在play-2.5.xscala-2.11项目中使用了以下版本:

libraryDependencies ++= List(
    "com.typesafe.play" %% "play-slick" % "2.1.0",
    "com.typesafe.play" %% "play-slick-evolutions" % "2.1.0",
    "com.typesafe.slick" %% "slick" % "3.2.0",
    "com.github.tototoshi" %% "slick-joda-mapper" % "2.3.0"
}

slick.backend.DatabaseConfig来自slick-3.1.0所需的play-slick-2.0.2。由于您需要slick-3.2.0,因此需要play-slick-2.1.0使用https://github.com/playframework/play-slickhttps://github.com/tototoshi/slick-joda-mapper