Quantcast
Channel: techscouting through the java news » Sönke Sothmann
Viewing all articles
Browse latest Browse all 72

Environment specific externalized Grails configuration

$
0
0

Grails supports environment specific configuration, which can be used to define different settings for development, test, production or custom environments. The Grails User Guide describes this feature in detail. E.g. you can define different database settings for development (use a local test database) and production (use a remote database).

Besides that, Grails supports externalized configuration (again see Grails User Guide). You can define one or more config files (properties or groovy config files supported). The contents of the config files will be merged with the Config.groovy config file in your application (external config file will override existing Config.groovy settings with the same name). This is extremly useful to separate database settings from your sourcecode.

Here is an example how you can define an external config file with the name of your app in the user’s home directory:

// Config.groovy
grails.config.locations = [ "file:${userHome}/${appName}-config.properties" ]

To get the best of both worlds, you can combine these two features: use a general external config file and one external config file for each environment. The environment specific config file will have precedence over the general external config file.

// Config.groovy
grails.config.locations = [ "file:${userHome}/${appName}-config.properties",
"file:${userHome}/${appName}-${grails.util.Environment.current.name}-config.properties" ]

When you start your app in development mode, the following external config files will be picked up (assuming your app has the name myapp):

myapp-config.properties
myapp-development-config.properties

When you start your app in production mode, a different environment specific config file will be picked up:

myapp-config.properties
myapp-production-config.properties

Einsortiert unter:Groovy and Grails Tagged: Config, Environment, grails

Viewing all articles
Browse latest Browse all 72