Config
Since 0.6, general Grails and application configuration that is not possible via convention is handled by the Config.groovy file in grails-app/conf
This file uses Groovy's ConfigSlurper that provides an enhanced properties file like format.
The Config.groovy file can be used to configure Log4j Logging
Built in Grails config options
Grails also provides the following configuration options:
- grails.enable.native2ascii - Set this to true if you require native2ascii conversion of Grails i18n properties files
| Code Block |
|---|
grails.enable.native2ascii=true |
Per environment Configuration
You can have per-environment configuration as shown below. A configuration property set outside of environments may be overridden. In the example shown below, setting will have a value of foo except when run in the production environment, in which case setting will have a value of bar.
| Code Block |
|---|
setting = "foo"
com.example.anything.setting = "something"
environments {
production {
setting = "bar"
}
}
|
Accessing the configuration from your code
There are two options for getting hold of the config object:
grailsApplication.config, where 'grailsApplication' is an instance of GrailsApplication;ConfigurationHolder.config
Here are some examples:
| Code Block |
|---|
// Accessing configuration data from a controller...
class MyController {
...
def list = {
def propValue = grailsApplication.config.setting
def otherPropValue = grailsApplication.config.com.example.anything.setting
...
}
...
}
// ...and from elsewhere
import org.codehaus.groovy.grails.commons.ConfigurationHolder
class Something {
def myData = ConfigurationHolder.config.setting
def myOtherData = ConfigurationHolder.config.com.example.anything.setting
...
}
|
Build Configuration
Since Grails 1.1 the installed pluginsare placed in your home directory under a .grails/[PROJECT NAME] directory. This can be changed by creating a configuration file called "BuildConfig.groovy" under the grails-app/conf directory with the following line in it.
| Code Block |
|---|
grails.project.plugins.dir="./plugins"
|