2

I'd like to store properties in a database tables and have defaults for those properties set in Config.groovy. For example, I want to put a default email address into Config.groovy:

app.send.report.to = 'me@example.com'

and then be able to override this in a database table (key, value columns...).

Is there a plugin (or functionality inside grails) to do this?

zoran119
  • 10,657
  • 12
  • 46
  • 88

3 Answers3

4

There is Dynamic Config Plugin.

It stores config property in ConfigProperty domain and merges properties from Config.groovy and from database using:

grailsApplication.config.merge(configObject)

You may want to look at the plugin source code. If plugin does not work for you, you can implement something similar to this.

This approach is useful when you have UI for editing config properties.

Andriy Budzinskyy
  • 1,971
  • 22
  • 28
1

Grails does not have functionality that I'm aware of to override configuration values from a database, but it shouldn't be that difficult to do. In your Config.groovy you could put the defaults, and then as part of your bootstrap process, you could generate a temporary config file that has the values from the database (a simple query and iteration over the results could be used to generate that temp file). Include that temp file as one of your grails config locations, and it will override any values that are in the Config.groovy

If your goal is to have a shared configuration file that is used by multiple grails apps, you might also look into using something like Zookeeper to manage the shared configuration, but that may be a bit overkill for a single config file.

Jeff Storey
  • 56,312
  • 72
  • 233
  • 406
0

Not quite what you're asking for, but depending on what you want to achieve the External Configuration Reload plugin might be of use. It helps you to override default properties (in runtime), but not by using the DB.

wwwclaes
  • 1,152
  • 8
  • 12