3

我一直在尝试让 SORM 与 Play Framework 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]
4

1 回答 1

5

好的。这不是一个错误。SORM 0.3.8依赖于Scala 2.10.1Play 2.1.x使用Scala 2.10.0。您得到的异常是由两个Scala版本的Play混合工件引起的。

要解决这个问题,您只需告诉Play使用正确的Scala版本,scalaVersion := "2.10.1"方法是在文件project/Build.scala中添加项目设置。

最终的构建脚本可能如下所示:

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 !
  )

}
于 2013-06-04T21:13:11.400 回答