[英]How do i set up a grails environment variable?
I have a folder in my d drive.files in this drive i am using in my controller.so in controller i am specifying tht folder name for to each file recurse.But after development files may be saved in any other drive.so I want have environment variable for it.how to do that我的 d 驱动器中有一个文件夹。我在 controller.so 在 controller 中使用这个驱动器中的文件有它的环境变量。如何做到这一点
It sounds like a configuration parameter would be better than an environment variable.听起来配置参数比环境变量更好。
Config.groovy
is environment aware, so you can specify different values for development, production, etc. Config.groovy
是环境感知的,因此您可以为开发、生产等指定不同的值。
environments {
production {
fileLocation = "D:/"
}
development {
fileLocation "/somewhere/else"
}
test {
fileLocation "/production/somewhere"
}
}
You can read the value of this parameter with:您可以通过以下方式读取此参数的值:
def fileLocation = org.codehaus.groovy.grails.commons.ConfigurationHolder.config?.fileLocation
in grails 1.4 ConfigurationHolder
is deprecated, so you should read config parameters using this instead:在 grails 1.4
ConfigurationHolder
已弃用,因此您应该使用以下方式读取配置参数:
def fileLocation = grailsApplication.config.fileLocation
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.