进入播放! 2.0配置变量在application.conf中? [英] Access Play! 2.0 configuration variables in application.conf?

查看:68
本文介绍了进入播放! 2.0配置变量在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.您应该使用依赖项注入来注入EnvironmentConfiguration,并使用它们来读取配置值:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆