开发者

Grails app not picking up data from config

I have three environments blocks in my Grails config file similar to this:

environments {
    production {
        grails.serverURL = "https://www.mysite.com"
    }
    development {
        grails.serverURL = "http://localhost:8080/${appName}"
    }
    test {
        grails.serverURL = "http://localhost:8080/${appName}"
    }
}

... // more code

envi开发者_运维知识库ronments {
    production {
        authnet.apiId = "123456"
        authnet.testAccount = "false"
    }
    development {
        authnet.apiId = "654321"
        authnet.testAccount = "true"
    }
    test {
        authnet.apiId = "654321"
        authnet.testAccount = "true"
    }
}

... // more code

environments {
    production {
        email.sales = 'sales@mysite.com'
    }
    development {
        email.sales = 'test@mysite.com'
    }
    test {
        email.sales = 'test@mysite.com'
    }
}

Somewhere in a controller:

println grailsApplication.config.grails.serverURL
println grailsApplication.config.authnet.apiId
println grailsApplication.config.email.sales

It prints out:

http://localhost:8080/myapp
[:]
test@mysite.com

So for some reason the app can't get data from some environments blocks. The stuff outside of environments blocks is fine. I noticed this issue with several different apps, different configs etc. Tried getting it with both grailsApplication and ConfigurationHolder. Is it a Grails bug or I'm doing something wrong? I'm running Grails 1.3.6


Your redefineing your configuration info several times. SInce your writing groovy code that gets executed instead of XML configuration your changes don't get automatically merged, multiple configuration blocks overwrite each other. You need to define everything in one block like

environments {
    development {
        grails.serverURL = "http://localhost:8080/${appName}"
        authnet.apiId = "654321"
        authnet.testAccount = "true"
    }
    test {
        grails.serverURL = "http://localhost:8080/${appName}"
        authnet.apiId = "654321"
        authnet.testAccount = "true"
    }
    production {
        grails.serverURL = "https://www.mysite.com"
        authnet.apiId = "123456"
        authnet.testAccount = "false"
        }


You're running using the development environment, therefore you are selecting the host and port from the development settings. By default,

grails run-app

runs the application using the development environment. To run it in production, either build a war file using the command grails war, and deploy it in a servlet container, or use:

grails prod run-app

See http://www.grails.org/Environments for more information.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜