如何在Play Scala应用程序中使用密钥

时间:2017-01-13 11:46:20

标签: scala playframework playframework-2.0 secret-key

我在Play Scala项目的 TransactionID 1 2 3 4 5 6 7 8 9 中有secret key

application.conf

如何在我的控制器或服务中使用它?

我尝试了# See http://www.playframework.com/documentation/latest/ApplicationSecret for more details. application.secret="........" ,它给了我错误application.secret。它给出了value secret is not a member of controllers.Application play.crypto.secret

1 个答案:

答案 0 :(得分:3)

播放提供Configuration对象以从application.conf键访问配置键。

以下是如何访问播放Configuration对象的权限。

class HomeController @Inject() (configuration: play.api.Configuration) extends Controller {
  def foo = Action {

    val appSecretString = configuration.underlying.getString("application.secret")

    //do something with app secret
    Ok(appSecretString) //app secret should not be exposed, just trying to show it on browser, but do not do this in production
  }
}