Search code examples
grailsconfigconfiguration-files

Grails external config file path


I'am about to set up a external config file. So I'm using the grails plugin

compile "org.grails.plugins:external-config:1.1.1"

I create the application.groovy that looks like this

grails.config.locations = [
    "/Users/username/application.properties"

]

And my application.config file is exactly in this place. By creating a normal file i have access to it and can read out of it. In my file i have three key value pairs like

firstkey=first
secondkey=second
thirdkey=third

Still this keys does not get added to my config file. In the class which is placed in the src directory i am able to call the config like this

Holders.config
//No result on calling one of the keys
Holders.config.thirdkey

Has anyone an idea what I have to do additional


Solution

  • grails.config.locations takes spring resource patterns

    Try

    grails.config.locations = [
            "file:///Users/username/application.properties"
        ]
    

    If the file is in the home directory of the user under which the app is running. You can even use

    grails.config.locations = [
                "~/application.properties"
            ]
    

    The examples are already there in docs here

    You can enable debug log level for logger grails.plugin.externalconfig. And it will log messages if any of your configured external config file is not found.

    logger("grails.plugin.externalconfig", DEBUG, ["STDOUT"])