Grails外部配置

时间:2013-07-02 09:33:52

标签: grails configuration

我将Log4jConfig.groovy放入grails-app/conf/configs/

我得到了这样的例外:

...nested exception is org.codehaus.groovy.grails.exceptions.GrailsConfigurationException: Class not found loading Grails application: configs.Log4jConfig

在我的Config.groovy中:

def configsLocation = [Log4jConfig]
environments {
    development {
        grails.config.locations = configsLocation
    }
}

提前致谢。

1 个答案:

答案 0 :(得分:1)

在指定配置位置时,您需要指定包configs。如下所示会产生适当的结果:

//Config.groovy
def configsLocation = [configs.Log4jConfig]
environments {
    development {
        grails.config.locations = configsLocation
    }
}

//grails-app/conf/configs/Log4jConfig.groovy
package configs //specify the package in config as well
my.foo = 1234
my.bar = "ABCD"

//Grails Console or Unit Test or render from controller
assert 1234 == grailsApplication.config.my.foo
assert "ABCD" == grailsApplication.config.my.bar