我在Play Scala项目的secret key
有application.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
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
}
}