【发布时间】:2014-03-14 13:35:18
【问题描述】:
我开始使用现有的 Grails 项目,这是处理外部配置文件的配置文件 (Config.groovy) 的一部分:
grails.config.locations = [];
def defaultConfigFile = "${basedir}/configs/BombayConfig.groovy"
def defaultDatasourceFile = "${basedir}/configs/BombayDataSource.groovy"
if(File.separator == "\\") {
defaultConfigFile = defaultConfigFile.replace('/', '\\')
defaultDatasourceFile = defaultDatasourceFile.replace('/', '\\')
}
String PROJECT_NAME = "BOMBAY"
String CONFIG_ENV = "${PROJECT_NAME}_CONFIG_LOCATION"
String DATASOURCE_ENV = "${PROJECT_NAME}_DATASOURCE_LOCATION"
def externalConfig = System.getenv(CONFIG_ENV)
def externalDataSource = System.getenv(DATASOURCE_ENV)
if (externalConfig && new File(externalConfig).isFile()) {
grails.config.locations << "file:" + externalConfig
}
else {
grails.config.locations << "file:" + defaultConfigFile
}
if (externalDataSource && new File(externalDataSource).isFile()) {
grails.config.locations << "file:" + externalDataSource
}
else {
grails.config.locations << "file:" + defaultDatasourceFile
}
我在 configs 文件夹中有一些默认文件,但在服务器中,正在使用的文件位于:
/home/someusername/configuration/
这看起来不像默认路径,并且没有配置建议的指向该路径的环境变量。
我还尝试查找链接到其他配置文件夹的配置文件夹,但没有找到任何内容。
我迷路了;配置文件还能如何指定给 Grails?
编辑: 为了澄清事情,服务器正在运行并工作,我只想弄清楚它是如何从上述指定路径中获取配置文件的。
【问题讨论】:
-
你确定这些环境变量没有被传递到服务器上的相关进程(Tomcat?)即使它们没有在你检查的任何shell中设置?通常当我需要设置这样的东西时,我会将环境设置放入 Tomcat 启动脚本中。
-
这就是我想念的伊恩,他们被设置在脚本中。谢谢!
标签: grails