我想将 api key 存储在我的 grails 应用程序中。 Api key 应该是全局的,并且可以每隔几分钟或几小时更改一次。
全局存储此 key 的最佳位置在哪里?
我不想将它存储在数据库中,猜测配置是最好的地方。
但我认为 config 是存储常量而不是可变数据的好地方。
那么,在哪里全局存储 api key 呢?
更新:可能是带有静态字段的类,如 String apiKey
会足够吗?
最佳答案
Api key should be global and can be changed every several minutes or hours.
为什么 API key 会如此频繁地更改?
guess that config is the best place. But I suppose that config is a good place to store constants, not changeable data.
通常属性在
Config.groovy
是只读的,但没有什么可以阻止您修改它们,例如class MyController {
def grailsApplication
def updateApiKey(String newKey) {
grailsApplication.config.apiKey = newKey
}
}
关于grails - 在 grails 中存储 api 客户端 key 的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24259875/