我一直在尝试让SORM与Play框架2.2-SNAPSHOT以及2.1.1一起工作。目前,我正试图运行一个简约的示例应用程序,我为了更容易地追踪问题而创建。不幸的是,我收到的错误信息对我一点帮助也没有。
val appDependencies = Seq(
"org.sorm-framework" % "sorm" % "0.3.8",
"com.h2database" % "h2" % "1.3.168"
)
# Database configuration
#
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"
# db.default.user=sa
# db.default.password=""
case class Car( brand: String, wheels: Int )
object Db extends Instance( Seq( Entity[Car]() ), "jdbc:h2:mem:play" )
object Application extends Controller {
def index = Action {
Db.query[Car].count()
Ok("hello wolrd")
}
}
结果:
play.api.Application$$anon$1: Execution exception[[RuntimeException: java.lang.NoSuchMethodError: scala.reflect.internal.TreeInfo.firstArgument(Lscala/reflect/internal/Trees$Tree;)Lscala/reflect/internal/Trees$Tree;]]
at play.api.Application$class.handleError(Application.scala:289) ~[play_2.10.jar:2.1.1]
at play.api.DefaultApplication.handleError(Application.scala:383) [play_2.10.jar:2.1.1]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$17$$anonfun$apply$24.apply(PlayDefaultUpstreamHandler.scala:326) [play_2.10.jar:2.1.1]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$17$$anonfun$apply$24.apply(PlayDefaultUpstreamHandler.scala:324) [play_2.10.jar:2.1.1]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.1]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.1]
java.lang.RuntimeException: java.lang.NoSuchMethodError: scala.reflect.internal.TreeInfo.firstArgument(Lscala/reflect/internal/Trees$Tree;)Lscala/reflect/internal/Trees$Tree;
at play.api.mvc.ActionBuilder$$anon$1.apply(Action.scala:222) ~[play_2.10.jar:2.1.1]
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$2$$anonfun$apply$5$$anonfun$apply$6.apply(Action.scala:109) ~[play_2.10.jar:2.1.1]
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$2$$anonfun$apply$5$$anonfun$apply$6.apply(Action.scala:109) ~[play_2.10.jar:2.1.1]
at play.utils.Threads$.withContextClassLoader(Threads.scala:18) ~[play_2.10.jar:2.1.1]
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$2$$anonfun$apply$5.apply(Action.scala:108) ~[play_2.10.jar:2.1.1]
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$2$$anonfun$apply$5.apply(Action.scala:106) ~[play_2.10.jar:2.1.1]
Caused by: java.lang.NoSuchMethodError: scala.reflect.internal.TreeInfo.firstArgument(Lscala/reflect/internal/Trees$Tree;)Lscala/reflect/internal/Trees$Tree;
at scala.tools.nsc.typechecker.Typers$Typer.parentTypes(Typers.scala:1550) ~[scala-compiler.jar:na]
at scala.tools.nsc.typechecker.Namers$Namer.templateSig(Namers.scala:861) ~[scala-compiler.jar:na]
at scala.tools.nsc.typechecker.Namers$Namer.getSig$1(Namers.scala:1300) ~[scala-compiler.jar:na]
at scala.tools.nsc.typechecker.Namers$Namer.typeSig(Namers.scala:1347) ~[scala-compiler.jar:na]
at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1$$anonfun$apply$1.apply$mcV$sp(Namers.scala:709) ~[scala-compiler.jar:na]
at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1$$anonfun$apply$1.apply(Namers.scala:708) ~[scala-compiler.jar:na]
好的。这不是bug。SORM 0.3.8依赖于Scala 2.10.1和Play 2.1。x使用Scala 2.10.0。你得到的异常是由Play混合来自Scala版本的工件引起的。
要解决这个问题,你所需要做的就是告诉Play使用正确的Scala版本,通过在project/Build.scala文件中的项目设置中添加scalaVersion := "2.10.1"
。
最终的构建脚本可能看起来像这样:
object ApplicationBuild extends Build {
val appName = "play-test"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
"org.sorm-framework" % "sorm" % "0.3.8",
"com.h2database" % "h2" % "1.3.168"
)
val main = play.Project(appName, appVersion, appDependencies).settings(
resolvers +=
"Local Maven Repository" at
"file:///"+Path.userHome.absolutePath+"/.m2/repository",
scalaVersion := "2.10.1" // <--- ! This is the fix !
)
}