Skip to content

Instantly share code, notes, and snippets.

@biancarosa
Last active October 15, 2015 22:50
Show Gist options
  • Save biancarosa/19c9cac8f6db52113b9b to your computer and use it in GitHub Desktop.
Save biancarosa/19c9cac8f6db52113b9b to your computer and use it in GitHub Desktop.
MyPluginGrailsPlugin
import grails.util.Environment
class MyGrailsPlugin {
/* plugin definitions */
def doWithSpring = {
loadPluginConfig(application.config)
}
/**
* Loads the asynchronous mail configuration.
*
* 1. Loads the grails configuration.
* 2. Merges it with the default plugin configuration.
* 3. Merges it with the user plugin configuration.
*/
private void loadPluginConfig(def config) {
GroovyClassLoader classLoader = new GroovyClassLoader(getClass().classLoader)
// merging default config into main application config
config.merge(new ConfigSlurper(Environment.current.name).parse(
classLoader.loadClass("DefaultMyPluginConfig"))
)
// merging user-defined config into main application config if provided
try {
config.merge(new ConfigSlurper(Environment.current.name).parse(
classLoader.loadClass("MyPluginConfig"))
)
} catch (Exception ignored) {
// ignore, just use the defaults
}
}
/* other methods */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment