Reputation:
I need to override grails.serverURL
at runtime without having to regenerate the application's WAR file. I have tried various ways of setting grails.serverURL
in the application.properties
file and cannot get it to work.
Here is the environment specific portion of Config.groovy
:
environments {
prod
{
grails.serverURL = "http://nonexistentserver.somecompany.com:8080"
grails.anotherappspecificURL = "xcc://user:[email protected]"
}
Basically, our application.properties
looks like this:
grails.env=prod
grails.war.deployed=true
app.grails.version=1.0.4
app.name=myapp
Below is one of the ways I have tried to override the settings. These are defined in Config.groovy
:
grails.serverURL=http://webserver1.somecompany.com:8080
grails.anotherappspecificURL=xcc://admin:[email protected]
Any help with getting this to work without having to make code changes would be greatly appreciated!
Upvotes: 2
Views: 6959
Reputation: 1244
I've found that externalized configuration is a little tricky (as of Grails 1.3.7). You have to put your file into grails.config.locations in Config.groovy
grails.config.locations << 'classpath:my-config-file.groovy'
But you can't access the properties without adding another file. I've made it work by putting a new configuration file into grails-app/conf
and adding it to the classpath by adding the following to scripts/Events.groovy
.
eventCompileEnd = {
ant.copy(todir:classesDirPath) {
fileset(file:"${basedir}/grails-app/conf/SecurityConfig.groovy")
}
}
You can find more information at https://stackoverflow.com/a/9789506/1269312
Upvotes: 0
Reputation: 11271
This may not be relevant, but I noticed you're missing quotation marks in your grails.serverURL
Upvotes: 0
Reputation: 11035
The proper way to override values in Config.groovy is to use an external properties file, see:
http://grails.org/doc/1.1.x/guide/3.%20Configuration.html#3.4%20Externalized%20Configuration
Specify an external properties file in Config.groovy, for example:
grails.config.locations = [ "classpath:app-config.properties"]
In the properties file (can be stored in grails-app/conf/) specify the override value:
grails.serverURL=http://webserver1.somecompany.com:8080
Anytime you need to change the serverURL once the war is deployed just modify the properties file in /WEB-INF/classes/app-config.properties and reload the context.
Upvotes: 3