简体   繁体   English

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

[英]How to use secret key in Play Scala application

I have secret key in application.conf of Play Scala project. 我在Play Scala项目的application.conf中有secret key

# See http://www.playframework.com/documentation/latest/ApplicationSecret for more details.
application.secret="........"

How do I use it in my controller or service? 如何在控制器或服务中使用它?

I tried with application.secret , it gives me error value secret is not a member of controllers.Application . 我尝试了application.secret ,它给我错误value secret is not a member of controllers.Application WIth play.crypto.secret it gives object crypto is not a member of package play play.crypto.secret提供给object crypto is not a member of package play

Play provides Configuration object to access configuration keys from the application.conf keys. Play提供了Configuration对象,用于从application.conf键访问配置键。

Here is how you can get access to play Configuration object. 这是您访问播放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
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM