2017-01-13 52 views
1

我在Play Scala项目的application.conf中有secret key如何在Play Scala应用程序中使用密钥

# 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

回答

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 
    } 
} 
+1

谢谢。我得到了'secretKey' –

+0

@PareshNagore接受如果你喜欢它 – pamu

相关问题