开发者

Write to config.groovy

I know it's possible to read in values from the grails-app/conf/Config.groovy but i was wondering if it i开发者_Python百科s possible to write values as well?

something as simple as this doesn't seem to actually change the value in the Config.

def oldValue = grailsApplication.config.my.value 
assert oldValue == "oldValue"

def newValue = "newValue"
grailsApplication.config.my.value = newValue 
assert newValue == grailsApplication.config.my.value

I would like to use this as a way to store some values outside of a database without having to load up another properties file.


That's probably not going to be practical if I understand you correctly. You're really dealing with the compiled Config.class at runtime. Do you really want to check out Config.groovy from your VCS, modify it, check it back in, recompile it, and mess around with the Classloader to reload it? The only way I have found to do this is by externalizing their properties a database or file and managing state at runtime to deal with updates.


I agree with proflux's comment. Config.groovy is not the right place to persist any data generated by your application, and it's a good thing that what you try doesn't work :)

I am very curious as to why you don't want to persist these values in a regular database (of whatever kind). There is, of course always the option of storing this in a file somewhere, the path of which you can configure in Config.groovy. But even that to me only seems marginally helpful.

Why not add a domain class along the lines of this:

class Setting{
  String key
  String value
  static constraints = {
    key(unique: true)
  }
}

This will probably be the easiest way of achieving what you're looking for, from what I can tell from here. But again, you should elaborate on what kind of data it is that you need to persist...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜