2017-01-13 86 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

相關問題