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"
    }
}

      

+2


a source to share


5 answers


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.

+2


a source


All ConfigSlurper variables are environment bound. What you showed above should work fine.



When you use grails run-app

, you are working in the development

default environment . Could this be your problem?

0


a source


Try ...

> grails prod run-app

      

This should give you bla (text) and foo (word)

> grails test run-app

      

This should give you bla (othertext) and foo (another word)

0


a source


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

      

0


a source


Check your Config.groovy that you have an import for the environment

import grails.util.Environment

      

Otherwise Environment.current is empty.

0


a source







All Articles