我试图对播放剪影种子样本做一些改进,目的是避免在postgres中手动创建表格。我试图遵循
中使用的实现https://github.com/playframework/play-slick/tree/master/samples/computer-database
,但是当我将一个bind(classOf [InitialData])。asEagerSingleton()添加到一个InitialData类时,我遇到了一些注入问题。我得到:注入构造函数的错误,java.lang.RuntimeException:没有启动的应用程序。我在
中上传了暂定的应用程序https://github.com/renexdev/Play-Auth-Slick-Seed-Load-Schema
。我修改了UserImpl.scala中的一些方法,但重要的文件是/app/modules/InitialData.scala,当应用程序启动时,它由一个绑定(classOf [InitialData])中的抽象模块调用.asEagerSingleton()。 我被建议将执行上下文传递给initialData类。我试过了 def doSomething(隐式ec:ExecutionContext) 建议在
https://github.com/alexandru/scala-best-practices/blob/master/sections/4-concurrency-parallelism.md
和导入play.api.libs.concurrent.Execution.Implicits._ 建议在
Play Framework 2.1 - Cannot find an implicit ExecutionContext
但没有成功。如果有人能给我一些关于注射或构造函数可能出错的见解,我将不胜感激。谢谢你的时间。 RENEX
答案 0 :(得分:1)
如果您将一个类绑定为渴望的单例,则必须注意您的代码不会引用静态Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim iconDoc As NotesDocument
Set db = session.CurrentDatabase
'NoteID of icon document from icon properties
Set iconDoc = db.GetDocumentById("11E")
'Delete the field $FormsTemplateFile
Call iconDoc.RemoveItem("$FormsTemplateFile")
Call iconDoc.Save(True, True)
End Sub
调用。 Guice绑定在Play应用程序启动之前连接,绑定为eager singleton的实例也将在应用程序启动之前实例化。因此,如果您在此代码中引用已启动的应用程序,则会看到错误“没有启动的应用程序”。
代码中的问题是play.api.Play.current
trait在静态引用DAOSlick
的帮助下静态创建DatabaseConfig
。您应该将play.api.Play.current
或DatabaseConfigProvider
实例注入DAO实现中。请查看Play Framework documentation应如何做到这一点。