进入播放! 2.0配置变量在application.conf中? [英] Access Play! 2.0 configuration variables in application.conf?
问题描述
以前在游戏中! v1确实很容易在application.conf
中定义配置变量,然后像这样访问它们:
Previously in Play! v1 it was really easy to define configuration variables in application.conf
and then access them like so:
play.configuration("db.driver")
但是,现在我无法在文档中找到与v2中类似用途或适当替代品有关的任何内容.这样做的方法是什么?
However now I can't find anything in the documentation for similar uses in v2 or a proper alternative. What's the method for doing so?
推荐答案
从Play 2.5开始,不推荐使用play.api.Play.current
.您应该使用依赖项注入来注入Environment
或Configuration
,并使用它们来读取配置值:
As of Play 2.5, play.api.Play.current
is deprecated. You should use dependency injection to inject the Environment
or Configuration
and use that to read the configuration value:
class HomeController @Inject() (configuration: play.api.Configuration) extends Controller {
def config = Action {
Ok(configuration.underlying.getString("db.driver"))
}
}
查看播放文档进行更详细的讨论.
Checkout the Play documentation for more detailed discussion.
这篇关于进入播放! 2.0配置变量在application.conf中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!