我正试图学习Play,Scala和Guice此刻,我遇到了与version 2.3.7 of Play有关的问题。当我通过更改插件启动示例时。 sbt的播放版本为2.3.6该应用程序的ApplicationController正常加载。但是,当在plugins.sbt中切换到2.3.7时,我只是得到一个空白页面。为什么Play v2.3.6与Guice一起使用但不能播放v2.3.7?
我组合了Play-Guice示例(使用早期版本的Play构建)和Slick数据访问示例。
这里是我的Application.scala播放器的代码,而包装和进口:
@Singleton
class Application @Inject() (textGenerator: TextGenerator) extends Controller {
def index = Action {
Ok(views.html.index(textGenerator.welcomeText))
}
}
object Application extends Controller {
def index = Action {
Ok(views.html.index("Your new application is ready.", "Home"))
}
}
这里是我的Global.scala(减去进口):
object Global extends GlobalSettings {
/**
* Bind types such that whenever TextGenerator is required, an instance of WelcomeTextGenerator will be used.
*/
val injector = Guice.createInjector(new AbstractModule {
protected def configure() {
bind(classOf[TextGenerator]).to(classOf[WelcomeTextGenerator])
}
})
/**
* Controllers must be resolved through the application context. There is a special method of GlobalSettings
* that we can override to resolve a given controller. This resolution is required by the Play router.
*/
override def getControllerInstance[A](controllerClass: Class[A]): A = injector.getInstance(controllerClass)
}
任何人都可以看到,为什么播放的一个版本会工作,但不是其他?
任何信息请求或受过教育的猜测也欢迎!
注意:到目前为止没有明显的错误信息,我在两个版本中看到的唯一区别是一个加载页面,另一个不加载页面。没有已知的记录错误,错误消息或代码差异(当然不包括版本切换)。
Build.scala(减去进口):
object ApplicationBuild extends Build {
val appName = "root"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
"com.google.inject" % "guice" % "3.0",
"javax.inject" % "javax.inject" % "1",
"org.mockito" % "mockito-core" % "1.9.5" % "test"
)
val main = Project(appName, file(".")).enablePlugins(play.PlayScala).settings(
version := appVersion,
libraryDependencies ++= appDependencies
)
}
SBT shell的任何输出? – Mikesname 2015-02-07 15:28:14
@Mikesname - 我在播放运行选项卡日志窗口中看不到太多,只是典型的启动消息。我会看看我是否可以确定是否有任何其他日志记录丢失。此外,我正在考虑将记录添加到控制器,这可能会有所帮助。 – 2015-02-07 15:40:07
我使用4.0-beta5,我的应用程序在2.3.7(及更早版本)上运行。 – 2015-02-09 09:02:12