[英]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.