使用scala 2.10.3在MacOS X 10.8.4上使用Play Framework 2.2.1,我有以下代码:
package controllers
import play.api._
object Global extends GlobalSettings {
override def onStart(app: Application) {
Logger.info("Application has started")
}
override def onStop(app: Application) {
Logger.info("Application shutdown...")
Store.shutdown()
Logger.info("Shutdown complete")
}
}
当我使用play run
的开发模式时,我得到以下内容:
[info] Loading project definition from /Users/jon/code/test/project
[info] Set current project to critter (in build file:/Users/jon/code/test/)
--- (Running the application from SBT, auto-reloading is enabled) ---
[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0%0:9000
(Server started, use Ctrl+D to stop and go back to the console...)
[info] Compiling 1 Scala source to /Users/jon/code/test/target/scala-2.10/classes...
[info] play - Application started (Dev)
[info] Compiling 1 Scala source to /Users/jon/code/test/target/scala-2.10/classes...
--- (RELOAD) ---
[info] play - Application started (Dev)
正如您在此处所看到的,我触发了一个请求,该请求导致应用程序被编译,然后处理了请求。我在源文件中插入了换行符并再次发出请求,以触发重新加载。 我没有收到有关应用程序关闭的消息。
我正在使用嵌入式数据库,所以我需要优雅地关闭它。如果我不能赶上关机,我不能那样做。我做错了什么,或者这是Play和自动重载的错误?
谢谢!
答案 0 :(得分:3)
并不总是需要在默认/ root包中。如果你想像你一样将它保存在控制器包中,你需要在application.conf中更改全局配置:
global = Global
来
global = controllers.Global
只是Global的默认值是root package。
答案 1 :(得分:0)