The mail plugin is documented to require its settings in Config.groovy. I want to have it stored in the database so it can be changed at runtime. And this is just one example.
I've read Does externalizing sensitive config variables into a .properties outside of Config.groovy provide a security advantage in Grails? but this is about using an external property file, I need to store the settings in the database (the app has an admin interface, with auditing and so on).
Thank you.
In Bootstrap.groovy
you can read the property values from the database and replace those read from the config files by updating grailsApplication.config
. For example, assume you want to replace the value of a config property named foo.bar
class BootStrap {
GrailsApplication grailsApplication
def init = { servletContext ->
def fooBarDB = // read the value of foo.bar from the database
grailsApplication.config.foo.bar = fooBarDB
}
}
Rather than writing this code yourself, you could instead use the Dynamic Config Plugin to achieve the same outcome.
Yes, you can do this. During the grails bootstrap process using Bootstrap.groovy
, retrieve the properties from the database and override them. It's similar to a properties file override, you're just storing them in a database.
Also see Properties in the database
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With