开发者

How to extend per environment configuration in grails

开发者 https://www.devze.com 2022-12-31 13:39 出处:网络
It seems that only grails.serverURL and grails.path are recognized as 开发者_如何学Cper environment configrautions. bla and foo are ignored and could not be used in application

It seems that only grails.serverURL and grails.path are recognized as 开发者_如何学Cper environment configrautions. bla and foo are ignored and could not be used in application Anyone could solves this and provide a way to get bla and foo configured per 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"
    }
}


Since Grails 3.0, both Groovy or YAML syntax can be used. The new main application configuration file is /conf/application.yml but you can continue to use your existing groovy configuration defining a /conf/application.groovy file.

This is an example of datasource definition per 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 a grails command in a specific environment you can use:

grails [environment] [command name]

To target an environment different from dev, test and prod you can use:

grails -Dgrails.env=myenv run-app

See the grails environment documentation or this example application for more information.


All the ConfigSlurper variables are scoped by environment. What you've shown above should work fine.

When you use grails run-app, you are running in the development environment by default. Could that be your issue?


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 (otherword)


Config.groovy setting

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 out when started with grails run-app

a b http://alpha.foo.dec /bard


Check in your Config.groovy that you have the import for Environment

import grails.util.Environment

Otherwise the Environment.current is empty.

0

精彩评论

暂无评论...
验证码 换一张
取 消