grails - 在 grails 中存储 api 客户端 key 的位置

标签 grails

我想将 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/

相关文章:

Grails 默认排序的 "hasMany"域属性

grails - Grails log4j配置

grails - 具有逻辑OR的Grails可搜索插件

java - 在Grails中运行集成测试时,如何解决HibernateGormStaticApi的java.lang.NoClassDefFoundError?

grails - Gradle 相当于 'grails -Dgrails.env=production run-app'

session - 如何在grails中使用 session

jquery - jQuery fullcalendar:IE中的事件(作为json feed)和事件(作为函数)问题

grails - SpringSource : Grails plugins

unit-testing - 使用 IVY 解析器进行 Grails 2.3 单元测试

spring - Grails 2.0 注入(inject) bean 并在 Controller 中出现 ClassCastException 错误