grails - 从环境变量将grails配置外部化为多个属性文件

我已经设置了这样的环境变量:

APP_HOME = "c:\app\app-datasource.properties

在config.groovy我
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.locationgrails.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/

相关文章:

grails - 在Grails中,是否可以将数据库迁移插件配置为在其他插件之前运行?

grails - Grails 应用程序中的 CMS

javascript - 如果弹出窗口被打开,则禁止刷新

grails - Grails-多个联接在 ListView 中显示冗余数据

exception - 保存操作时出现 MissingMethodException

hibernate - Grails数据源 “Cannot add or update a chil

mongodb - 在grails中,如何让transactionManager是mongoTran

grails - Grails UI性能插件页面压缩问题

grails - 使设计适应 Grails

jquery - 克隆一个动态创建的选择列表