如何在grails中扩展每个环境的配置
根据环境配置,似乎只识别grails.serverURL和grails.path。bla和foo被忽略,无法在应用程序中使用 任何人都可以解决这个问题,并提供一种方法,让每个环境配置bla和foo如何在grails中扩展每个环境的配置,grails,environment,config,Grails,Environment,Config,根据环境配置,似乎只识别grails.serverURL和grails.path。bla和foo被忽略,无法在应用程序中使用 任何人都可以解决这个问题,并提供一种方法,让每个环境配置bla和foo environments { production { grails.serverURL = "http://alpha.foo.de" grails.path = "" bla = "text" foo= "word"
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"
}
}
所有ConfigSlurper变量的作用域均由环境确定。你上面展示的应该很好用 当您使用
grailsrun-app
时,默认情况下您是在开发
环境中运行的。这可能是你的问题吗?试试
> grails prod run-app
这应该给你bla(文本)和foo(单词)
这将为您提供bla(othertext)和foo(otherword)Config.groovy设置
environments {
development {
grails.serverURL = "http://alpha.foo.de"
grails.path = "/bar"
staticServerURL = "http://static.foo.de"
staticPath = "/static"
}
}
源代码索引.gsp
${grailsApplication.config.staticServerURL}a
${grailsApplication.config.staticPath}b
${grailsApplication.config.grails.serverURL}c
${grailsApplication.config.grails.path}d
使用grails run应用程序启动时打印出什么内容
a b http://alpha.foo.dec /bard
在Config.groovy中检查您是否具有环境导入
import grails.util.Environment
否则Environment.current为空。自从Grails 3.0以来,Groovy或YAML语法都可以使用。新的主应用程序配置文件是
/conf/application.yml
,但您可以继续使用现有的groovy配置来定义/conf/application.groovy
文件
这是每个环境的数据源定义示例(以YAML为单位):
要在特定环境中运行grails命令,可以使用:
grails [environment] [command name]
grails -Dgrails.env=myenv run-app
要针对不同于dev、test和prod的环境,您可以使用:
grails [environment] [command name]
grails -Dgrails.env=myenv run-app
有关更多信息,请参阅或。如何访问blah和foo?你能发布一些对那些属性不返回任何内容的代码吗?你如何从服务中访问这些东西?它不适用于grailsApplication.config.blah…请参阅问题。