How to extend environment config in grails
It seems that only grails.serverURL and grails.path are recognized as per environment config. bla and foo are ignored and cannot be used in the application. Can anyone solve this problem and provide a way to configure bla and foo for each environment?
environments {
production {
grails.serverURL = "http://alpha.foo.de"
grails.path = ""
bla = "text"
foo= "word"
}
test {
grails.serverURL = "http://test.foo.de"
grails.path = ""
bla = "othertext"
foo= "otherword"
}
}
a source to share
Since Grails 3.0 can use both Groovy and YAML syntax. New main application configuration file /conf/application.yml
, but you can continue to use the existing Groovy configuration defining the /conf/application.groovy
.
This is an example of defining a data source for an environment (in YAML):
environments:
development:
dataSource:
dbCreate: create-drop
url: jdbc:h2:mem:devDb
test:
dataSource:
dbCreate: update
url: jdbc:h2:mem:testDb
production:
dataSource:
dbCreate: update
url: jdbc:h2:prodDb
myenv:
dataSource:
dbCreate: update
url: jdbc:h2:myenvDb
To run grails command in a specific environment, you can use:
grails [environment] [command name]
To target an environment other than dev, test, and prod, you can use:
grails -Dgrails.env=myenv run-app
See the Grails environment documentation or this sample application for more information.
a source to share
Config.groovy setup
environments {
development {
grails.serverURL = "http://alpha.foo.de"
grails.path = "/bar"
staticServerURL = "http://static.foo.de"
staticPath = "/static"
}
}
source code index.gsp
${grailsApplication.config.staticServerURL}a
${grailsApplication.config.staticPath}b
${grailsApplication.config.grails.serverURL}c
${grailsApplication.config.grails.path}d
what is printed on startup with grails run-app
a b http://alpha.foo.dec /bard
a source to share