如何在 grails 中扩展每个环境的配置
根据环境配置,似乎只有 grails.serverURL 和 grails.path 被识别。 bla 和 foo 被忽略并且无法在应用程序中使用 任何人都可以解决这个问题并提供一种根据环境配置 bla 和 foo 的方法吗?
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"
}
}
It seems that only grails.serverURL and grails.path are recognized as per 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"
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
从 Grails 3.0 开始,Groovy 或 YAML 语法都可以使用。新的主应用程序配置文件是
/conf/application.yml
但您可以继续使用现有的 groovy 配置来定义/conf/application.groovy
文件。这是每个环境的数据源定义示例(在 YAML 中):
要在特定环境中运行 grails 命令,您可以使用:
要针对不同于 dev、test 和 prod 的环境,您可以使用:
请参阅 grails 环境文档 或 此示例应用程序了解更多信息。
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):
To run a grails command in a specific environment you can use:
To target an environment different from dev, test and prod you can use:
See the grails environment documentation or this example application for more information.
所有 ConfigSlurper 变量的范围均受环境限制。您上面显示的内容应该可以正常工作。
当您使用
grails run-app
时,默认情况下您在开发
环境中运行。这可能是你的问题吗?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 thedevelopment
environment by default. Could that be your issue?尝试...
这应该给你 bla(文本)和 foo(单词)
这应该给你 bla(其他文本)和 foo(其他单词)
Try...
This should give you bla (text) and foo (word)
This should give you bla (othertext) and foo (otherword)
config.groovy设置
源代码index.gsp
用grails run-app启动时打印出什么
Config.groovy setting
source code index.gsp
what is printed out when started with grails run-app
检查您的 Config.groovy 是否已导入环境,
否则,Environment.current 为空。
Check in your Config.groovy that you have the import for Environment
Otherwise the Environment.current is empty.