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

问题描述 投票:1回答:1

我在Play Scala项目的secret keyapplication.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它给object crypto is not a member of package play

scala playframework playframework-2.0 secret-key
1个回答
3
投票

Play提供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
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.