Reputation: 6136
Hypothetical situation:
I have downloaded a Grails application from the web as a WAR file, foo.war
. In the documentation it says that I can put my own custom configuration in /foo.groovy
, because this path is included in grails.config.locations
in Config.groovy
. I can dump all my custom config in that one file and life is good.
How, here's my problem... The configuration for FooApp is big and hairy, and I don't want it all in one file. I would like to break it up into /bar.groovy
and /baz.groovy
to keep things organized. Is there a way to specify something in /foo.groovy
so that FooApp will also pick up /bar.groovy
and /baz.groovy
and process them?
I already tried appending paths to grails.config.locations
in /foo.groovy
, but Grails didn't like that and threw a nasty exception on startup. I'm not sure what other approach to take.
Edit for clarity:
grails-app/conf/Config.groovy
looks like this:
grails.config.locations = ["file:/foo.groovy"]
Now, without modifying grails-app/conf/Config.groovy
, and only by modifying /foo.groovy
, is there a way to load more config files other than /foo.groovy
?
Upvotes: 2
Views: 789
Reputation: 3881
You could slurp the additional config files within foo.groovy
:
foo.groovy
port {
to {
somewhere=8080
another {
place=7070
}
}
}
host = new ConfigSlurper().parse(new File("bar.groovy").toURL())
bar.groovy
to {
somewhere="http://localhost/"
another {
place="https://another.place.com/"
}
}
So within your app you have:
assert grailsApplication.config.port.to.somewhere == 8080
assert grailsApplication.config.port.to.another.place == 7070
assert grailsApplication.config.host.to.somewhere == "http://localhost/"
assert grailsApplication.config.host.to.another.place == "https://another.place.com/"
Upvotes: 2