无法使Global类正常工作

时间:2013-11-27 09:43:33

标签: scala playframework sbt playframework-2.1

我一次又一次地在运行时遇到同样的错误:

Cannot initialize the custom Global object (%s) (perhaps it's a wrong reference?)
In me/myapp/conf/application.conf at line 5.
application.global=common.Global

其中

package common

object Global extends GlobalSettings {
  //...
}

顺便说一句,我在Contoller的动作中使用Global

奇怪的是,如果我在application.global=common.Global

中注释掉/conf/application.conf
# application.global=common.Global  

然后错误就会消失。

我正在使用Scala 2.10.3Play 2.1.3和sbt.version = 0.12.4

//project/build.properties
sbt.version=0.12.4


//project/Build.scala
object ApplicationBuild extends Build {
  //.....
  lazy val buildSettings = Seq(
    organization := "myapp",
    version := "1.0-SNAPSHOT123",
    scalaVersion := "2.10.3"
  )
}



//project/plugins.sbt

// Comment to get more information during initialization
logLevel := Level.Warn

// The Typesafe repository 
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

// Use the Play sbt plugin for Play projects
addSbtPlugin("play" % "sbt-plugin" % "2.1.3")

你的想法?

2 个答案:

答案 0 :(得分:3)

确保您的common包放在app文件夹内和/或检查名称中的拼写错误。像魅力一样。

错误消失,因为它是Play的默认行为 - 如果默认路径中没有Global对象,它只会认为根本不存在。

答案 1 :(得分:0)

也可能与app配置调用的循环引用有关的问题:

https://github.com/playframework/playframework/issues/883