简体   繁体   中英

externalizing grails config into multiple properties files from environment variable

I have setup an environment variable like this:

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

in config.groovy I do

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."
    }

I got this from a post online, I want to know if we need to use grails.config.location or grails.config.locations ? Also instead of APP_HOME being set to the properties file directly, can I set it to a directory path (eg: c:\\apps) and then can I have multiple properties files placed in that directory, then if I do the following multiple times will it work?:

    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...

Thanks in advance

You need to modify grails.config.locations (plural). My (very limited) experience says that the external files are probably not loaded until after Config.groovy is completed.

You might want to consider looking for he additional configuration file on your classpath; then you can put your extra outside of the Grails project (eg, in your web server's library) or within the grails-app/conf directory. I have written the instructions on how to do that here .

Here's a post on how to do it from a plugin: https://stackoverflow.com/a/9789506/1269312

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM