我已经设置了这样的环境变量:
APP_HOME = "c:\app\app-datasource.properties
def ENV_NAME = "APP_HOME"
if(!grails.config.location || !(grails.config.location instanceof List)) {
grails.config.location = []
}
if(System.getenv(ENV_NAME)) {
println "Including configuration file specified in environment: " + System.getenv(ENV_NAME);
grails.config.location << "file:" + System.getenv(ENV_NAME)
} else if(System.getProperty(ENV_NAME)) {
println "Including configuration file specified on command line: " + System.getProperty(ENV_NAME);
grails.config.location << "file:" + System.getProperty(ENV_NAME)
} else {
println "No external configuration file defined."
}
grails.config.location
或grails.config.locations
?APP_HOME
设置为属性文件,而是可以将其设置为目录路径(e.g.: c:\apps)
,然后可以在该目录中放置多个属性文件,那么如果多次执行以下操作,它将起作用吗: grails.config.locations << "file:" + System.getProperty(ENV_NAME)+ "\app-datasource.properties"
grails.config.locations << "file:" + System.getProperty(ENV_NAME)+ "\app-reporting.properties"
and so on...
最佳答案
您需要修改grails.config.locations
(复数)。我的经验(非常有限)说,在Config.groovy
完成之前,可能不会加载外部文件。
您可能要考虑在您的类路径中寻找其他配置文件。那么您可以将多余的内容放在Grails项目之外(例如,放在Web服务器的库中)或grails-app/conf
目录中。我已经写了有关如何执行here的说明。
这是有关如何通过插件执行操作的文章:https://stackoverflow.com/a/9789506/1269312
https://stackoverflow.com/questions/9856235/