views:

1278

answers:

2

I need to override grails.serverURL at runtime WITHOUT having to regenerate the application WAR file. I have tried various ways of setting the grails.serverURL in the application.properties file and cannot get it to work.

Here is the environment specific portion of the 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 the Config.groovy file


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!

Regards,

Allen

A: 

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.

John Wagenleitner
Yup, I got that from the documentation. Problem is, it isn't working. Our Config.groovy doesn't have anything set for grails.config.location (it's commented out), so I assume that the default external properties file is "application.properties". It appears that is the case since I can change the setting for "grails.env" and it picks up the proper "environment" configuration that was defined in Config.groovy.However, I want to override those settings with something else at runtime startup and doing as you noted doesn't have any affect on any of the grails.<propertyname> settings.
To clarify my original post, the last "code" section is in the application.properties file, not the Config.groovy file, as the comment before that code section might suggest.
I believe the application.properties contains application meta data that is not merged in with the configuration data contained in Config.groovy. Therefore, in order to override a parameter that would normally be set in Config.groovy you need to use grails.config.location and not application.properties.
John Wagenleitner
I understood your last code section was from application.properties and the point of my answer was to say that is not the correct place (i.e., wont work) to override config values.
John Wagenleitner
A: 

Thanks for the reply. I thought that might be what you were referring to. will try that and post back. The grails docs should be a little more clearer regarding the fact that application.properties not being the place to put values that you are trying to override.