當Global.scala
中的代碼執行時,application.conf
已經加載了嗎?我問,因爲我試圖從Global.scala
讀取一些配置項目,我總是得到None
。有什麼解決方法嗎?什麼時候播放加載application.conf?
2
A
回答
1
在Java中它的可用beforeStart(Application app)
已經
public class Global extends GlobalSettings {
public void beforeStart(Application app) {
String secret = Play.application().configuration().getString("application.secret");
play.Logger.debug("Before start secret is: " + secret);
super.beforeStart(app);
}
}
,因爲它的要求,即在配置數據庫連接,最有可能Scala works the same way(無法查詢)
1
這裏下面是如何做到這之後它讀取配置已加載,但之前的應用程序實際上開始:
import play.api.{Configuration, Mode}
import play.api.GlobalSettings
import java.io.File
import utils.apidocs.InfoHelper
object Global extends GlobalSettings {
override def onLoadConfig(
config: Configuration,
path: File, classloader:
ClassLoader,
mode: Mode.Mode): Configuration = {
InfoHelper.loadApiInfo(config)
config
}
}
在這裏,下面,只爲您的信息,是個的InfoHelper.loadApiInfo
–Ë源,它只是加載API信息爲揚鞭UI:
package utils.apidocs
import play.api.Configuration
import com.wordnik.swagger.config._
import com.wordnik.swagger.model._
object InfoHelper {
def loadApiInfo(config: Configuration) = {
config.getString("application.name").map { appName =>
config.getString("application.domain").map { appDomain =>
config.getString("application.emails.apiteam").map { contact =>
val apiInfo = ApiInfo(
title = s"$appName API",
description = s"""
Fantastic application that makes you smile. You can find our
more about $appName at <a href="//$appDomain">$appDomain</a>.
""",
termsOfServiceUrl = s"//$appDomain/terms",
contact = contact,
license = s"$appName Subscription and Services Agreement",
licenseUrl = s"//$appDomain/license"
)
ConfigFactory.config.info = Some(apiInfo)
}}}
}
}
我希望它能幫助。
相關問題
- 1. Android設備加密 - 它什麼時候開始播放?
- 2. 播放框架dinamic ip application.conf
- 3. 播放application.conf - 測試CONFIGS
- 4. 什麼時候釋放GObject?
- 5. 什麼時候UITabBarController的視圖加載?
- 6. 什麼時候加載IIS7太多了?
- 7. 什麼時候加載紋理?
- 8. 什麼時候加入名字,什麼時候不加入?
- 9. 什麼時候在休眠時使用Lazy加載/ Eager加載?
- 10. 如何知道什麼時候使用聲音播放聲音播放
- 11. 什麼時候Windows.InvalidateRect過載
- 12. 如何知道tonegenerator什麼時候停止播放
- 13. 什麼時候在MusicTrack中播放MIDINoteMessage? iOS的
- 14. 什麼時候播放器(_:wantsToQuitMatch :)被調用?
- 15. 播放application.conf數據庫設置?
- 16. 什麼時候會播出「com.android.vending.INSTALL_REFERRER」get send?
- 17. Math.random()是什麼時候播種?
- 18. JMX-Spring - 什麼時候播出'JMXNotification'?
- 19. 什麼時候你把Javascript放在body裏,什麼時候在頭,什麼時候用doc.load?
- 20. 什麼時候放棄MVVM有意義?
- 21. 什麼時候開始考慮縮放?
- 22. 什麼時候釋放變量decodeSet1?
- 23. 什麼時候會釋放一個autorelease
- 24. 什麼時候在splitViewController中放置final?
- 25. 什麼時候應該釋放內存?
- 26. 什麼時候需要釋放內存?
- 27. libSpotifySDK:加載播放列表時超時
- 28. 你什麼時候重載operator new?
- 29. SCCM什麼時候下載更新
- 30. 什麼時候下載/構建SBT包?
在我的情況下,正確的地方是onLoadConfig ...但你的答案真的很有幫助。非常感謝你。 – j3d
添加適當的解決方案,然後爲其他人:) – biesior
好吧,看看下面我的完整答案:-) – j3d