How to use an external configuration file .groovy in Grails 3

Section 24.3 in the external configuration indicates that the file .properties or .yml can be used for external configuration, but I'd like to see my external config file to be .groovy , my file application.groovy , which I have already converted from .yml . How can i do this?

Version Grails 3.2.0.M2

UPDATE:

I was able to get the job done on the basis of the responses provided by @Michal_Szulc

Please note that for ConfigSlurper necessary that the current environment to work properly. Also note that these changes should be made to the file my_grails_app/grails-app/init/my_grails_app/Application.groovy , and not in the file my_grails_app/grails-app/conf/application.groovy , which may occur if you converted configuration .yml configuration .groovy .

 package my_grails_app import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration import org.springframework.context.EnvironmentAware import org.springframework.core.env.Environment import org.springframework.core.env.MapPropertySource class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main( String[] args ) { GrailsApp.run( Application, args ) } @Override void setEnvironment( Environment environment ) { def appName = grails.util.Metadata.current.getApplicationName() // The value of this environment variable should be the absolute path to an external .groovy config file like /opt/my_grails_app/my_grails_app-config.groovy. def envVarName = "MY_GRAILS_APP_CONFIG" // If you don't want to use an environment variable you can specify your external .groovy config file here, but the environment variable will still be checked first. def dfltAppConfigFileName = "/opt/${ appName }/${ appName }-config.groovy" def appConfigFile = null def loadDfltConfig = false // Try to load config specified by the environment variable first println "Checking the environment variable ${ envVarName } for the configuration file location..." def envVarVal = System.getenv( envVarName ) ?: System.getProperty( envVarName ) if( envVarVal ) { appConfigFile = new File( envVarVal ) if( !appConfigFile.exists() ) { println "The configuration file ${ appConfigFile } specified by the environment variable ${ envVarName } does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } } else { println "The environment variable ${ envVarName } which specifies the configuration file to be loaded does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } // Try loading the default config file since we couldn't find one specified by the environment variable if( loadDfltConfig ) { appConfigFile = new File( dfltAppConfigFileName ) if( !appConfigFile.exists() ) { println "The default configuration file ${ dfltAppConfigFileName } does not exist." appConfigFile = null } } // Load the config file if it exists, otherwise exit if( appConfigFile ) { println "Loading configuration file ${ appConfigFile }" def config = new ConfigSlurper( environment.activeProfiles.first() ).parse( appConfigFile.toURI().toURL() ) environment.propertySources.addFirst( new MapPropertySource( "${ appName }-config", config ) ) } else { println "No configuration file found. Exiting." System.exit( 1 ) } ) { package my_grails_app import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration import org.springframework.context.EnvironmentAware import org.springframework.core.env.Environment import org.springframework.core.env.MapPropertySource class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main( String[] args ) { GrailsApp.run( Application, args ) } @Override void setEnvironment( Environment environment ) { def appName = grails.util.Metadata.current.getApplicationName() // The value of this environment variable should be the absolute path to an external .groovy config file like /opt/my_grails_app/my_grails_app-config.groovy. def envVarName = "MY_GRAILS_APP_CONFIG" // If you don't want to use an environment variable you can specify your external .groovy config file here, but the environment variable will still be checked first. def dfltAppConfigFileName = "/opt/${ appName }/${ appName }-config.groovy" def appConfigFile = null def loadDfltConfig = false // Try to load config specified by the environment variable first println "Checking the environment variable ${ envVarName } for the configuration file location..." def envVarVal = System.getenv( envVarName ) ?: System.getProperty( envVarName ) if( envVarVal ) { appConfigFile = new File( envVarVal ) if( !appConfigFile.exists() ) { println "The configuration file ${ appConfigFile } specified by the environment variable ${ envVarName } does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } } else { println "The environment variable ${ envVarName } which specifies the configuration file to be loaded does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } // Try loading the default config file since we couldn't find one specified by the environment variable if( loadDfltConfig ) { appConfigFile = new File( dfltAppConfigFileName ) if( !appConfigFile.exists() ) { println "The default configuration file ${ dfltAppConfigFileName } does not exist." appConfigFile = null } } // Load the config file if it exists, otherwise exit if( appConfigFile ) { println "Loading configuration file ${ appConfigFile }" def config = new ConfigSlurper( environment.activeProfiles.first() ).parse( appConfigFile.toURI().toURL() ) environment.propertySources.addFirst( new MapPropertySource( "${ appName }-config", config ) ) } else { println "No configuration file found. Exiting." System.exit( 1 ) } be the absolute path to an external .groovy config file like /opt/my_grails_app/my_grails_app-config.groovy. package my_grails_app import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration import org.springframework.context.EnvironmentAware import org.springframework.core.env.Environment import org.springframework.core.env.MapPropertySource class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main( String[] args ) { GrailsApp.run( Application, args ) } @Override void setEnvironment( Environment environment ) { def appName = grails.util.Metadata.current.getApplicationName() // The value of this environment variable should be the absolute path to an external .groovy config file like /opt/my_grails_app/my_grails_app-config.groovy. def envVarName = "MY_GRAILS_APP_CONFIG" // If you don't want to use an environment variable you can specify your external .groovy config file here, but the environment variable will still be checked first. def dfltAppConfigFileName = "/opt/${ appName }/${ appName }-config.groovy" def appConfigFile = null def loadDfltConfig = false // Try to load config specified by the environment variable first println "Checking the environment variable ${ envVarName } for the configuration file location..." def envVarVal = System.getenv( envVarName ) ?: System.getProperty( envVarName ) if( envVarVal ) { appConfigFile = new File( envVarVal ) if( !appConfigFile.exists() ) { println "The configuration file ${ appConfigFile } specified by the environment variable ${ envVarName } does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } } else { println "The environment variable ${ envVarName } which specifies the configuration file to be loaded does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } // Try loading the default config file since we couldn't find one specified by the environment variable if( loadDfltConfig ) { appConfigFile = new File( dfltAppConfigFileName ) if( !appConfigFile.exists() ) { println "The default configuration file ${ dfltAppConfigFileName } does not exist." appConfigFile = null } } // Load the config file if it exists, otherwise exit if( appConfigFile ) { println "Loading configuration file ${ appConfigFile }" def config = new ConfigSlurper( environment.activeProfiles.first() ).parse( appConfigFile.toURI().toURL() ) environment.propertySources.addFirst( new MapPropertySource( "${ appName }-config", config ) ) } else { println "No configuration file found. Exiting." System.exit( 1 ) } an environment variable you can specify your external .groovy config file here, but the environment variable will still be checked first. package my_grails_app import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration import org.springframework.context.EnvironmentAware import org.springframework.core.env.Environment import org.springframework.core.env.MapPropertySource class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main( String[] args ) { GrailsApp.run( Application, args ) } @Override void setEnvironment( Environment environment ) { def appName = grails.util.Metadata.current.getApplicationName() // The value of this environment variable should be the absolute path to an external .groovy config file like /opt/my_grails_app/my_grails_app-config.groovy. def envVarName = "MY_GRAILS_APP_CONFIG" // If you don't want to use an environment variable you can specify your external .groovy config file here, but the environment variable will still be checked first. def dfltAppConfigFileName = "/opt/${ appName }/${ appName }-config.groovy" def appConfigFile = null def loadDfltConfig = false // Try to load config specified by the environment variable first println "Checking the environment variable ${ envVarName } for the configuration file location..." def envVarVal = System.getenv( envVarName ) ?: System.getProperty( envVarName ) if( envVarVal ) { appConfigFile = new File( envVarVal ) if( !appConfigFile.exists() ) { println "The configuration file ${ appConfigFile } specified by the environment variable ${ envVarName } does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } } else { println "The environment variable ${ envVarName } which specifies the configuration file to be loaded does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } // Try loading the default config file since we couldn't find one specified by the environment variable if( loadDfltConfig ) { appConfigFile = new File( dfltAppConfigFileName ) if( !appConfigFile.exists() ) { println "The default configuration file ${ dfltAppConfigFileName } does not exist." appConfigFile = null } } // Load the config file if it exists, otherwise exit if( appConfigFile ) { println "Loading configuration file ${ appConfigFile }" def config = new ConfigSlurper( environment.activeProfiles.first() ).parse( appConfigFile.toURI().toURL() ) environment.propertySources.addFirst( new MapPropertySource( "${ appName }-config", config ) ) } else { println "No configuration file found. Exiting." System.exit( 1 ) } {appName} / $ {appName} -config.groovy" package my_grails_app import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration import org.springframework.context.EnvironmentAware import org.springframework.core.env.Environment import org.springframework.core.env.MapPropertySource class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main( String[] args ) { GrailsApp.run( Application, args ) } @Override void setEnvironment( Environment environment ) { def appName = grails.util.Metadata.current.getApplicationName() // The value of this environment variable should be the absolute path to an external .groovy config file like /opt/my_grails_app/my_grails_app-config.groovy. def envVarName = "MY_GRAILS_APP_CONFIG" // If you don't want to use an environment variable you can specify your external .groovy config file here, but the environment variable will still be checked first. def dfltAppConfigFileName = "/opt/${ appName }/${ appName }-config.groovy" def appConfigFile = null def loadDfltConfig = false // Try to load config specified by the environment variable first println "Checking the environment variable ${ envVarName } for the configuration file location..." def envVarVal = System.getenv( envVarName ) ?: System.getProperty( envVarName ) if( envVarVal ) { appConfigFile = new File( envVarVal ) if( !appConfigFile.exists() ) { println "The configuration file ${ appConfigFile } specified by the environment variable ${ envVarName } does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } } else { println "The environment variable ${ envVarName } which specifies the configuration file to be loaded does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } // Try loading the default config file since we couldn't find one specified by the environment variable if( loadDfltConfig ) { appConfigFile = new File( dfltAppConfigFileName ) if( !appConfigFile.exists() ) { println "The default configuration file ${ dfltAppConfigFileName } does not exist." appConfigFile = null } } // Load the config file if it exists, otherwise exit if( appConfigFile ) { println "Loading configuration file ${ appConfigFile }" def config = new ConfigSlurper( environment.activeProfiles.first() ).parse( appConfigFile.toURI().toURL() ) environment.propertySources.addFirst( new MapPropertySource( "${ appName }-config", config ) ) } else { println "No configuration file found. Exiting." System.exit( 1 ) } environment variable first package my_grails_app import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration import org.springframework.context.EnvironmentAware import org.springframework.core.env.Environment import org.springframework.core.env.MapPropertySource class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main( String[] args ) { GrailsApp.run( Application, args ) } @Override void setEnvironment( Environment environment ) { def appName = grails.util.Metadata.current.getApplicationName() // The value of this environment variable should be the absolute path to an external .groovy config file like /opt/my_grails_app/my_grails_app-config.groovy. def envVarName = "MY_GRAILS_APP_CONFIG" // If you don't want to use an environment variable you can specify your external .groovy config file here, but the environment variable will still be checked first. def dfltAppConfigFileName = "/opt/${ appName }/${ appName }-config.groovy" def appConfigFile = null def loadDfltConfig = false // Try to load config specified by the environment variable first println "Checking the environment variable ${ envVarName } for the configuration file location..." def envVarVal = System.getenv( envVarName ) ?: System.getProperty( envVarName ) if( envVarVal ) { appConfigFile = new File( envVarVal ) if( !appConfigFile.exists() ) { println "The configuration file ${ appConfigFile } specified by the environment variable ${ envVarName } does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } } else { println "The environment variable ${ envVarName } which specifies the configuration file to be loaded does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } // Try loading the default config file since we couldn't find one specified by the environment variable if( loadDfltConfig ) { appConfigFile = new File( dfltAppConfigFileName ) if( !appConfigFile.exists() ) { println "The default configuration file ${ dfltAppConfigFileName } does not exist." appConfigFile = null } } // Load the config file if it exists, otherwise exit if( appConfigFile ) { println "Loading configuration file ${ appConfigFile }" def config = new ConfigSlurper( environment.activeProfiles.first() ).parse( appConfigFile.toURI().toURL() ) environment.propertySources.addFirst( new MapPropertySource( "${ appName }-config", config ) ) } else { println "No configuration file found. Exiting." System.exit( 1 ) } envVarName} for the configuration file location ..." package my_grails_app import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration import org.springframework.context.EnvironmentAware import org.springframework.core.env.Environment import org.springframework.core.env.MapPropertySource class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main( String[] args ) { GrailsApp.run( Application, args ) } @Override void setEnvironment( Environment environment ) { def appName = grails.util.Metadata.current.getApplicationName() // The value of this environment variable should be the absolute path to an external .groovy config file like /opt/my_grails_app/my_grails_app-config.groovy. def envVarName = "MY_GRAILS_APP_CONFIG" // If you don't want to use an environment variable you can specify your external .groovy config file here, but the environment variable will still be checked first. def dfltAppConfigFileName = "/opt/${ appName }/${ appName }-config.groovy" def appConfigFile = null def loadDfltConfig = false // Try to load config specified by the environment variable first println "Checking the environment variable ${ envVarName } for the configuration file location..." def envVarVal = System.getenv( envVarName ) ?: System.getProperty( envVarName ) if( envVarVal ) { appConfigFile = new File( envVarVal ) if( !appConfigFile.exists() ) { println "The configuration file ${ appConfigFile } specified by the environment variable ${ envVarName } does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } } else { println "The environment variable ${ envVarName } which specifies the configuration file to be loaded does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } // Try loading the default config file since we couldn't find one specified by the environment variable if( loadDfltConfig ) { appConfigFile = new File( dfltAppConfigFileName ) if( !appConfigFile.exists() ) { println "The default configuration file ${ dfltAppConfigFileName } does not exist." appConfigFile = null } } // Load the config file if it exists, otherwise exit if( appConfigFile ) { println "Loading configuration file ${ appConfigFile }" def config = new ConfigSlurper( environment.activeProfiles.first() ).parse( appConfigFile.toURI().toURL() ) environment.propertySources.addFirst( new MapPropertySource( "${ appName }-config", config ) ) } else { println "No configuration file found. Exiting." System.exit( 1 ) } ? System.getProperty (envVarName) package my_grails_app import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration import org.springframework.context.EnvironmentAware import org.springframework.core.env.Environment import org.springframework.core.env.MapPropertySource class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main( String[] args ) { GrailsApp.run( Application, args ) } @Override void setEnvironment( Environment environment ) { def appName = grails.util.Metadata.current.getApplicationName() // The value of this environment variable should be the absolute path to an external .groovy config file like /opt/my_grails_app/my_grails_app-config.groovy. def envVarName = "MY_GRAILS_APP_CONFIG" // If you don't want to use an environment variable you can specify your external .groovy config file here, but the environment variable will still be checked first. def dfltAppConfigFileName = "/opt/${ appName }/${ appName }-config.groovy" def appConfigFile = null def loadDfltConfig = false // Try to load config specified by the environment variable first println "Checking the environment variable ${ envVarName } for the configuration file location..." def envVarVal = System.getenv( envVarName ) ?: System.getProperty( envVarName ) if( envVarVal ) { appConfigFile = new File( envVarVal ) if( !appConfigFile.exists() ) { println "The configuration file ${ appConfigFile } specified by the environment variable ${ envVarName } does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } } else { println "The environment variable ${ envVarName } which specifies the configuration file to be loaded does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } // Try loading the default config file since we couldn't find one specified by the environment variable if( loadDfltConfig ) { appConfigFile = new File( dfltAppConfigFileName ) if( !appConfigFile.exists() ) { println "The default configuration file ${ dfltAppConfigFileName } does not exist." appConfigFile = null } } // Load the config file if it exists, otherwise exit if( appConfigFile ) { println "Loading configuration file ${ appConfigFile }" def config = new ConfigSlurper( environment.activeProfiles.first() ).parse( appConfigFile.toURI().toURL() ) environment.propertySources.addFirst( new MapPropertySource( "${ appName }-config", config ) ) } else { println "No configuration file found. Exiting." System.exit( 1 ) } } specified by the environment variable $ {envVarName} does not exist. Checking for the default configuration file $ {dfltAppConfigFileName} instead ..." package my_grails_app import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration import org.springframework.context.EnvironmentAware import org.springframework.core.env.Environment import org.springframework.core.env.MapPropertySource class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main( String[] args ) { GrailsApp.run( Application, args ) } @Override void setEnvironment( Environment environment ) { def appName = grails.util.Metadata.current.getApplicationName() // The value of this environment variable should be the absolute path to an external .groovy config file like /opt/my_grails_app/my_grails_app-config.groovy. def envVarName = "MY_GRAILS_APP_CONFIG" // If you don't want to use an environment variable you can specify your external .groovy config file here, but the environment variable will still be checked first. def dfltAppConfigFileName = "/opt/${ appName }/${ appName }-config.groovy" def appConfigFile = null def loadDfltConfig = false // Try to load config specified by the environment variable first println "Checking the environment variable ${ envVarName } for the configuration file location..." def envVarVal = System.getenv( envVarName ) ?: System.getProperty( envVarName ) if( envVarVal ) { appConfigFile = new File( envVarVal ) if( !appConfigFile.exists() ) { println "The configuration file ${ appConfigFile } specified by the environment variable ${ envVarName } does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } } else { println "The environment variable ${ envVarName } which specifies the configuration file to be loaded does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } // Try loading the default config file since we couldn't find one specified by the environment variable if( loadDfltConfig ) { appConfigFile = new File( dfltAppConfigFileName ) if( !appConfigFile.exists() ) { println "The default configuration file ${ dfltAppConfigFileName } does not exist." appConfigFile = null } } // Load the config file if it exists, otherwise exit if( appConfigFile ) { println "Loading configuration file ${ appConfigFile }" def config = new ConfigSlurper( environment.activeProfiles.first() ).parse( appConfigFile.toURI().toURL() ) environment.propertySources.addFirst( new MapPropertySource( "${ appName }-config", config ) ) } else { println "No configuration file found. Exiting." System.exit( 1 ) } } which specifies the configuration file to be loaded does not exist. Checking for the default configuration file $ {dfltAppConfigFileName} instead ..." package my_grails_app import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration import org.springframework.context.EnvironmentAware import org.springframework.core.env.Environment import org.springframework.core.env.MapPropertySource class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main( String[] args ) { GrailsApp.run( Application, args ) } @Override void setEnvironment( Environment environment ) { def appName = grails.util.Metadata.current.getApplicationName() // The value of this environment variable should be the absolute path to an external .groovy config file like /opt/my_grails_app/my_grails_app-config.groovy. def envVarName = "MY_GRAILS_APP_CONFIG" // If you don't want to use an environment variable you can specify your external .groovy config file here, but the environment variable will still be checked first. def dfltAppConfigFileName = "/opt/${ appName }/${ appName }-config.groovy" def appConfigFile = null def loadDfltConfig = false // Try to load config specified by the environment variable first println "Checking the environment variable ${ envVarName } for the configuration file location..." def envVarVal = System.getenv( envVarName ) ?: System.getProperty( envVarName ) if( envVarVal ) { appConfigFile = new File( envVarVal ) if( !appConfigFile.exists() ) { println "The configuration file ${ appConfigFile } specified by the environment variable ${ envVarName } does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } } else { println "The environment variable ${ envVarName } which specifies the configuration file to be loaded does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } // Try loading the default config file since we couldn't find one specified by the environment variable if( loadDfltConfig ) { appConfigFile = new File( dfltAppConfigFileName ) if( !appConfigFile.exists() ) { println "The default configuration file ${ dfltAppConfigFileName } does not exist." appConfigFile = null } } // Load the config file if it exists, otherwise exit if( appConfigFile ) { println "Loading configuration file ${ appConfigFile }" def config = new ConfigSlurper( environment.activeProfiles.first() ).parse( appConfigFile.toURI().toURL() ) environment.propertySources.addFirst( new MapPropertySource( "${ appName }-config", config ) ) } else { println "No configuration file found. Exiting." System.exit( 1 ) } we could not find one specified by the environment variable package my_grails_app import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration import org.springframework.context.EnvironmentAware import org.springframework.core.env.Environment import org.springframework.core.env.MapPropertySource class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main( String[] args ) { GrailsApp.run( Application, args ) } @Override void setEnvironment( Environment environment ) { def appName = grails.util.Metadata.current.getApplicationName() // The value of this environment variable should be the absolute path to an external .groovy config file like /opt/my_grails_app/my_grails_app-config.groovy. def envVarName = "MY_GRAILS_APP_CONFIG" // If you don't want to use an environment variable you can specify your external .groovy config file here, but the environment variable will still be checked first. def dfltAppConfigFileName = "/opt/${ appName }/${ appName }-config.groovy" def appConfigFile = null def loadDfltConfig = false // Try to load config specified by the environment variable first println "Checking the environment variable ${ envVarName } for the configuration file location..." def envVarVal = System.getenv( envVarName ) ?: System.getProperty( envVarName ) if( envVarVal ) { appConfigFile = new File( envVarVal ) if( !appConfigFile.exists() ) { println "The configuration file ${ appConfigFile } specified by the environment variable ${ envVarName } does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } } else { println "The environment variable ${ envVarName } which specifies the configuration file to be loaded does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } // Try loading the default config file since we couldn't find one specified by the environment variable if( loadDfltConfig ) { appConfigFile = new File( dfltAppConfigFileName ) if( !appConfigFile.exists() ) { println "The default configuration file ${ dfltAppConfigFileName } does not exist." appConfigFile = null } } // Load the config file if it exists, otherwise exit if( appConfigFile ) { println "Loading configuration file ${ appConfigFile }" def config = new ConfigSlurper( environment.activeProfiles.first() ).parse( appConfigFile.toURI().toURL() ) environment.propertySources.addFirst( new MapPropertySource( "${ appName }-config", config ) ) } else { println "No configuration file found. Exiting." System.exit( 1 ) } dfltAppConfigFileName} does not exist." package my_grails_app import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration import org.springframework.context.EnvironmentAware import org.springframework.core.env.Environment import org.springframework.core.env.MapPropertySource class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main( String[] args ) { GrailsApp.run( Application, args ) } @Override void setEnvironment( Environment environment ) { def appName = grails.util.Metadata.current.getApplicationName() // The value of this environment variable should be the absolute path to an external .groovy config file like /opt/my_grails_app/my_grails_app-config.groovy. def envVarName = "MY_GRAILS_APP_CONFIG" // If you don't want to use an environment variable you can specify your external .groovy config file here, but the environment variable will still be checked first. def dfltAppConfigFileName = "/opt/${ appName }/${ appName }-config.groovy" def appConfigFile = null def loadDfltConfig = false // Try to load config specified by the environment variable first println "Checking the environment variable ${ envVarName } for the configuration file location..." def envVarVal = System.getenv( envVarName ) ?: System.getProperty( envVarName ) if( envVarVal ) { appConfigFile = new File( envVarVal ) if( !appConfigFile.exists() ) { println "The configuration file ${ appConfigFile } specified by the environment variable ${ envVarName } does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } } else { println "The environment variable ${ envVarName } which specifies the configuration file to be loaded does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } // Try loading the default config file since we couldn't find one specified by the environment variable if( loadDfltConfig ) { appConfigFile = new File( dfltAppConfigFileName ) if( !appConfigFile.exists() ) { println "The default configuration file ${ dfltAppConfigFileName } does not exist." appConfigFile = null } } // Load the config file if it exists, otherwise exit if( appConfigFile ) { println "Loading configuration file ${ appConfigFile }" def config = new ConfigSlurper( environment.activeProfiles.first() ).parse( appConfigFile.toURI().toURL() ) environment.propertySources.addFirst( new MapPropertySource( "${ appName }-config", config ) ) } else { println "No configuration file found. Exiting." System.exit( 1 ) } , otherwise exit package my_grails_app import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration import org.springframework.context.EnvironmentAware import org.springframework.core.env.Environment import org.springframework.core.env.MapPropertySource class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main( String[] args ) { GrailsApp.run( Application, args ) } @Override void setEnvironment( Environment environment ) { def appName = grails.util.Metadata.current.getApplicationName() // The value of this environment variable should be the absolute path to an external .groovy config file like /opt/my_grails_app/my_grails_app-config.groovy. def envVarName = "MY_GRAILS_APP_CONFIG" // If you don't want to use an environment variable you can specify your external .groovy config file here, but the environment variable will still be checked first. def dfltAppConfigFileName = "/opt/${ appName }/${ appName }-config.groovy" def appConfigFile = null def loadDfltConfig = false // Try to load config specified by the environment variable first println "Checking the environment variable ${ envVarName } for the configuration file location..." def envVarVal = System.getenv( envVarName ) ?: System.getProperty( envVarName ) if( envVarVal ) { appConfigFile = new File( envVarVal ) if( !appConfigFile.exists() ) { println "The configuration file ${ appConfigFile } specified by the environment variable ${ envVarName } does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } } else { println "The environment variable ${ envVarName } which specifies the configuration file to be loaded does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } // Try loading the default config file since we couldn't find one specified by the environment variable if( loadDfltConfig ) { appConfigFile = new File( dfltAppConfigFileName ) if( !appConfigFile.exists() ) { println "The default configuration file ${ dfltAppConfigFileName } does not exist." appConfigFile = null } } // Load the config file if it exists, otherwise exit if( appConfigFile ) { println "Loading configuration file ${ appConfigFile }" def config = new ConfigSlurper( environment.activeProfiles.first() ).parse( appConfigFile.toURI().toURL() ) environment.propertySources.addFirst( new MapPropertySource( "${ appName }-config", config ) ) } else { println "No configuration file found. Exiting." System.exit( 1 ) } }" package my_grails_app import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration import org.springframework.context.EnvironmentAware import org.springframework.core.env.Environment import org.springframework.core.env.MapPropertySource class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main( String[] args ) { GrailsApp.run( Application, args ) } @Override void setEnvironment( Environment environment ) { def appName = grails.util.Metadata.current.getApplicationName() // The value of this environment variable should be the absolute path to an external .groovy config file like /opt/my_grails_app/my_grails_app-config.groovy. def envVarName = "MY_GRAILS_APP_CONFIG" // If you don't want to use an environment variable you can specify your external .groovy config file here, but the environment variable will still be checked first. def dfltAppConfigFileName = "/opt/${ appName }/${ appName }-config.groovy" def appConfigFile = null def loadDfltConfig = false // Try to load config specified by the environment variable first println "Checking the environment variable ${ envVarName } for the configuration file location..." def envVarVal = System.getenv( envVarName ) ?: System.getProperty( envVarName ) if( envVarVal ) { appConfigFile = new File( envVarVal ) if( !appConfigFile.exists() ) { println "The configuration file ${ appConfigFile } specified by the environment variable ${ envVarName } does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } } else { println "The environment variable ${ envVarName } which specifies the configuration file to be loaded does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } // Try loading the default config file since we couldn't find one specified by the environment variable if( loadDfltConfig ) { appConfigFile = new File( dfltAppConfigFileName ) if( !appConfigFile.exists() ) { println "The default configuration file ${ dfltAppConfigFileName } does not exist." appConfigFile = null } } // Load the config file if it exists, otherwise exit if( appConfigFile ) { println "Loading configuration file ${ appConfigFile }" def config = new ConfigSlurper( environment.activeProfiles.first() ).parse( appConfigFile.toURI().toURL() ) environment.propertySources.addFirst( new MapPropertySource( "${ appName }-config", config ) ) } else { println "No configuration file found. Exiting." System.exit( 1 ) } )) .parse (appConfigFile.toURI (). toURL ()) package my_grails_app import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration import org.springframework.context.EnvironmentAware import org.springframework.core.env.Environment import org.springframework.core.env.MapPropertySource class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main( String[] args ) { GrailsApp.run( Application, args ) } @Override void setEnvironment( Environment environment ) { def appName = grails.util.Metadata.current.getApplicationName() // The value of this environment variable should be the absolute path to an external .groovy config file like /opt/my_grails_app/my_grails_app-config.groovy. def envVarName = "MY_GRAILS_APP_CONFIG" // If you don't want to use an environment variable you can specify your external .groovy config file here, but the environment variable will still be checked first. def dfltAppConfigFileName = "/opt/${ appName }/${ appName }-config.groovy" def appConfigFile = null def loadDfltConfig = false // Try to load config specified by the environment variable first println "Checking the environment variable ${ envVarName } for the configuration file location..." def envVarVal = System.getenv( envVarName ) ?: System.getProperty( envVarName ) if( envVarVal ) { appConfigFile = new File( envVarVal ) if( !appConfigFile.exists() ) { println "The configuration file ${ appConfigFile } specified by the environment variable ${ envVarName } does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } } else { println "The environment variable ${ envVarName } which specifies the configuration file to be loaded does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } // Try loading the default config file since we couldn't find one specified by the environment variable if( loadDfltConfig ) { appConfigFile = new File( dfltAppConfigFileName ) if( !appConfigFile.exists() ) { println "The default configuration file ${ dfltAppConfigFileName } does not exist." appConfigFile = null } } // Load the config file if it exists, otherwise exit if( appConfigFile ) { println "Loading configuration file ${ appConfigFile }" def config = new ConfigSlurper( environment.activeProfiles.first() ).parse( appConfigFile.toURI().toURL() ) environment.propertySources.addFirst( new MapPropertySource( "${ appName }-config", config ) ) } else { println "No configuration file found. Exiting." System.exit( 1 ) } appName} -config", config)) package my_grails_app import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration import org.springframework.context.EnvironmentAware import org.springframework.core.env.Environment import org.springframework.core.env.MapPropertySource class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main( String[] args ) { GrailsApp.run( Application, args ) } @Override void setEnvironment( Environment environment ) { def appName = grails.util.Metadata.current.getApplicationName() // The value of this environment variable should be the absolute path to an external .groovy config file like /opt/my_grails_app/my_grails_app-config.groovy. def envVarName = "MY_GRAILS_APP_CONFIG" // If you don't want to use an environment variable you can specify your external .groovy config file here, but the environment variable will still be checked first. def dfltAppConfigFileName = "/opt/${ appName }/${ appName }-config.groovy" def appConfigFile = null def loadDfltConfig = false // Try to load config specified by the environment variable first println "Checking the environment variable ${ envVarName } for the configuration file location..." def envVarVal = System.getenv( envVarName ) ?: System.getProperty( envVarName ) if( envVarVal ) { appConfigFile = new File( envVarVal ) if( !appConfigFile.exists() ) { println "The configuration file ${ appConfigFile } specified by the environment variable ${ envVarName } does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } } else { println "The environment variable ${ envVarName } which specifies the configuration file to be loaded does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } // Try loading the default config file since we couldn't find one specified by the environment variable if( loadDfltConfig ) { appConfigFile = new File( dfltAppConfigFileName ) if( !appConfigFile.exists() ) { println "The default configuration file ${ dfltAppConfigFileName } does not exist." appConfigFile = null } } // Load the config file if it exists, otherwise exit if( appConfigFile ) { println "Loading configuration file ${ appConfigFile }" def config = new ConfigSlurper( environment.activeProfiles.first() ).parse( appConfigFile.toURI().toURL() ) environment.propertySources.addFirst( new MapPropertySource( "${ appName }-config", config ) ) } else { println "No configuration file found. Exiting." System.exit( 1 ) } ." package my_grails_app import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration import org.springframework.context.EnvironmentAware import org.springframework.core.env.Environment import org.springframework.core.env.MapPropertySource class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main( String[] args ) { GrailsApp.run( Application, args ) } @Override void setEnvironment( Environment environment ) { def appName = grails.util.Metadata.current.getApplicationName() // The value of this environment variable should be the absolute path to an external .groovy config file like /opt/my_grails_app/my_grails_app-config.groovy. def envVarName = "MY_GRAILS_APP_CONFIG" // If you don't want to use an environment variable you can specify your external .groovy config file here, but the environment variable will still be checked first. def dfltAppConfigFileName = "/opt/${ appName }/${ appName }-config.groovy" def appConfigFile = null def loadDfltConfig = false // Try to load config specified by the environment variable first println "Checking the environment variable ${ envVarName } for the configuration file location..." def envVarVal = System.getenv( envVarName ) ?: System.getProperty( envVarName ) if( envVarVal ) { appConfigFile = new File( envVarVal ) if( !appConfigFile.exists() ) { println "The configuration file ${ appConfigFile } specified by the environment variable ${ envVarName } does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } } else { println "The environment variable ${ envVarName } which specifies the configuration file to be loaded does not exist. Checking for the default configuration file ${ dfltAppConfigFileName } instead..." appConfigFile = null loadDfltConfig = true } // Try loading the default config file since we couldn't find one specified by the environment variable if( loadDfltConfig ) { appConfigFile = new File( dfltAppConfigFileName ) if( !appConfigFile.exists() ) { println "The default configuration file ${ dfltAppConfigFileName } does not exist." appConfigFile = null } } // Load the config file if it exists, otherwise exit if( appConfigFile ) { println "Loading configuration file ${ appConfigFile }" def config = new ConfigSlurper( environment.activeProfiles.first() ).parse( appConfigFile.toURI().toURL() ) environment.propertySources.addFirst( new MapPropertySource( "${ appName }-config", config ) ) } else { println "No configuration file found. Exiting." System.exit( 1 ) } 
+5
source share
2 answers

I found this thread and quote from Graeme Rocher:

3 Grails uses Spring concept of funding sources, so she decides the properties of the system, environment, and, finally, application.yml / application.groovy

and Clyde Balneovy code:

 class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main(String[] args) { GrailsApp.run(Application) } @Override void setEnvironment(Environment environment) { //Set up Configuration directory def krakenHome = System.getenv('KRAKEN_HOME') ?: System.getProperty('KRAKEN_HOME') ?: "/opt/kraken" println "" println "Loading configuration from ${krakenHome}" def appConfigured = new File(krakenHome, 'KrakenConfig.groovy').exists() println "Loading configuration file ${new File(krakenHome, 'KrakenConfig.groovy')}" println "Config file found : " + appConfigured if (appConfigured) { def config = new ConfigSlurper().parse(new File(krakenHome, 'KrakenConfig.groovy').toURL()) environment.propertySources.addFirst(new MapPropertySource("KrakenConfig", config)) } } } ) { class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main(String[] args) { GrailsApp.run(Application) } @Override void setEnvironment(Environment environment) { //Set up Configuration directory def krakenHome = System.getenv('KRAKEN_HOME') ?: System.getProperty('KRAKEN_HOME') ?: "/opt/kraken" println "" println "Loading configuration from ${krakenHome}" def appConfigured = new File(krakenHome, 'KrakenConfig.groovy').exists() println "Loading configuration file ${new File(krakenHome, 'KrakenConfig.groovy')}" println "Config file found : " + appConfigured if (appConfigured) { def config = new ConfigSlurper().parse(new File(krakenHome, 'KrakenConfig.groovy').toURL()) environment.propertySources.addFirst(new MapPropertySource("KrakenConfig", config)) } } } ):? System.getProperty ( 'KRAKEN_HOME'):? "/ opt / kraken" class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main(String[] args) { GrailsApp.run(Application) } @Override void setEnvironment(Environment environment) { //Set up Configuration directory def krakenHome = System.getenv('KRAKEN_HOME') ?: System.getProperty('KRAKEN_HOME') ?: "/opt/kraken" println "" println "Loading configuration from ${krakenHome}" def appConfigured = new File(krakenHome, 'KrakenConfig.groovy').exists() println "Loading configuration file ${new File(krakenHome, 'KrakenConfig.groovy')}" println "Config file found : " + appConfigured if (appConfigured) { def config = new ConfigSlurper().parse(new File(krakenHome, 'KrakenConfig.groovy').toURL()) environment.propertySources.addFirst(new MapPropertySource("KrakenConfig", config)) } } } }" class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main(String[] args) { GrailsApp.run(Application) } @Override void setEnvironment(Environment environment) { //Set up Configuration directory def krakenHome = System.getenv('KRAKEN_HOME') ?: System.getProperty('KRAKEN_HOME') ?: "/opt/kraken" println "" println "Loading configuration from ${krakenHome}" def appConfigured = new File(krakenHome, 'KrakenConfig.groovy').exists() println "Loading configuration file ${new File(krakenHome, 'KrakenConfig.groovy')}" println "Config file found : " + appConfigured if (appConfigured) { def config = new ConfigSlurper().parse(new File(krakenHome, 'KrakenConfig.groovy').toURL()) environment.propertySources.addFirst(new MapPropertySource("KrakenConfig", config)) } } } 'KrakenConfig.groovy'). exists () class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main(String[] args) { GrailsApp.run(Application) } @Override void setEnvironment(Environment environment) { //Set up Configuration directory def krakenHome = System.getenv('KRAKEN_HOME') ?: System.getProperty('KRAKEN_HOME') ?: "/opt/kraken" println "" println "Loading configuration from ${krakenHome}" def appConfigured = new File(krakenHome, 'KrakenConfig.groovy').exists() println "Loading configuration file ${new File(krakenHome, 'KrakenConfig.groovy')}" println "Config file found : " + appConfigured if (appConfigured) { def config = new ConfigSlurper().parse(new File(krakenHome, 'KrakenConfig.groovy').toURL()) environment.propertySources.addFirst(new MapPropertySource("KrakenConfig", config)) } } } File (krakenHome, 'KrakenConfig.groovy')}" class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main(String[] args) { GrailsApp.run(Application) } @Override void setEnvironment(Environment environment) { //Set up Configuration directory def krakenHome = System.getenv('KRAKEN_HOME') ?: System.getProperty('KRAKEN_HOME') ?: "/opt/kraken" println "" println "Loading configuration from ${krakenHome}" def appConfigured = new File(krakenHome, 'KrakenConfig.groovy').exists() println "Loading configuration file ${new File(krakenHome, 'KrakenConfig.groovy')}" println "Config file found : " + appConfigured if (appConfigured) { def config = new ConfigSlurper().parse(new File(krakenHome, 'KrakenConfig.groovy').toURL()) environment.propertySources.addFirst(new MapPropertySource("KrakenConfig", config)) } } } appConfigured class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main(String[] args) { GrailsApp.run(Application) } @Override void setEnvironment(Environment environment) { //Set up Configuration directory def krakenHome = System.getenv('KRAKEN_HOME') ?: System.getProperty('KRAKEN_HOME') ?: "/opt/kraken" println "" println "Loading configuration from ${krakenHome}" def appConfigured = new File(krakenHome, 'KrakenConfig.groovy').exists() println "Loading configuration file ${new File(krakenHome, 'KrakenConfig.groovy')}" println "Config file found : " + appConfigured if (appConfigured) { def config = new ConfigSlurper().parse(new File(krakenHome, 'KrakenConfig.groovy').toURL()) environment.propertySources.addFirst(new MapPropertySource("KrakenConfig", config)) } } } parse (new File (krakenHome, 'KrakenConfig.groovy'). toURL ()) class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main(String[] args) { GrailsApp.run(Application) } @Override void setEnvironment(Environment environment) { //Set up Configuration directory def krakenHome = System.getenv('KRAKEN_HOME') ?: System.getProperty('KRAKEN_HOME') ?: "/opt/kraken" println "" println "Loading configuration from ${krakenHome}" def appConfigured = new File(krakenHome, 'KrakenConfig.groovy').exists() println "Loading configuration file ${new File(krakenHome, 'KrakenConfig.groovy')}" println "Config file found : " + appConfigured if (appConfigured) { def config = new ConfigSlurper().parse(new File(krakenHome, 'KrakenConfig.groovy').toURL()) environment.propertySources.addFirst(new MapPropertySource("KrakenConfig", config)) } } } , config)) class Application extends GrailsAutoConfiguration implements EnvironmentAware { static void main(String[] args) { GrailsApp.run(Application) } @Override void setEnvironment(Environment environment) { //Set up Configuration directory def krakenHome = System.getenv('KRAKEN_HOME') ?: System.getProperty('KRAKEN_HOME') ?: "/opt/kraken" println "" println "Loading configuration from ${krakenHome}" def appConfigured = new File(krakenHome, 'KrakenConfig.groovy').exists() println "Loading configuration file ${new File(krakenHome, 'KrakenConfig.groovy')}" println "Config file found : " + appConfigured if (appConfigured) { def config = new ConfigSlurper().parse(new File(krakenHome, 'KrakenConfig.groovy').toURL()) environment.propertySources.addFirst(new MapPropertySource("KrakenConfig", config)) } } } 
+2
source

Perhaps you can also try this method (Overriding run method)

 import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration import grails.util.Environment import grails.util.Holders import org.springframework.boot.CommandLineRunner class Application extends GrailsAutoConfiguration implements CommandLineRunner { static void main(String[] args) { GrailsApp.run(Application, args) } @Override void run(final String... args) throws Exception { println "Running in ${Environment.current.name}" // Get configuration from Holders. def config = Holders.getConfig() def locations = config.grails.config.locations locations.each { String configFileName = it.split("file:")[1] File configFile = new File(configFileName) if (configFile.exists()) { config.merge(new ConfigSlurper(Environment.current.name).parse(configFile.text)) } } } } ) { import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration import grails.util.Environment import grails.util.Holders import org.springframework.boot.CommandLineRunner class Application extends GrailsAutoConfiguration implements CommandLineRunner { static void main(String[] args) { GrailsApp.run(Application, args) } @Override void run(final String... args) throws Exception { println "Running in ${Environment.current.name}" // Get configuration from Holders. def config = Holders.getConfig() def locations = config.grails.config.locations locations.each { String configFileName = it.split("file:")[1] File configFile = new File(configFileName) if (configFile.exists()) { config.merge(new ConfigSlurper(Environment.current.name).parse(configFile.text)) } } } } throws Exception { import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration import grails.util.Environment import grails.util.Holders import org.springframework.boot.CommandLineRunner class Application extends GrailsAutoConfiguration implements CommandLineRunner { static void main(String[] args) { GrailsApp.run(Application, args) } @Override void run(final String... args) throws Exception { println "Running in ${Environment.current.name}" // Get configuration from Holders. def config = Holders.getConfig() def locations = config.grails.config.locations locations.each { String configFileName = it.split("file:")[1] File configFile = new File(configFileName) if (configFile.exists()) { config.merge(new ConfigSlurper(Environment.current.name).parse(configFile.text)) } } } } " import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration import grails.util.Environment import grails.util.Holders import org.springframework.boot.CommandLineRunner class Application extends GrailsAutoConfiguration implements CommandLineRunner { static void main(String[] args) { GrailsApp.run(Application, args) } @Override void run(final String... args) throws Exception { println "Running in ${Environment.current.name}" // Get configuration from Holders. def config = Holders.getConfig() def locations = config.grails.config.locations locations.each { String configFileName = it.split("file:")[1] File configFile = new File(configFileName) if (configFile.exists()) { config.merge(new ConfigSlurper(Environment.current.name).parse(configFile.text)) } } } } ") [ import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration import grails.util.Environment import grails.util.Holders import org.springframework.boot.CommandLineRunner class Application extends GrailsAutoConfiguration implements CommandLineRunner { static void main(String[] args) { GrailsApp.run(Application, args) } @Override void run(final String... args) throws Exception { println "Running in ${Environment.current.name}" // Get configuration from Holders. def config = Holders.getConfig() def locations = config.grails.config.locations locations.each { String configFileName = it.split("file:")[1] File configFile = new File(configFileName) if (configFile.exists()) { config.merge(new ConfigSlurper(Environment.current.name).parse(configFile.text)) } } } } (configFile.text)) import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration import grails.util.Environment import grails.util.Holders import org.springframework.boot.CommandLineRunner class Application extends GrailsAutoConfiguration implements CommandLineRunner { static void main(String[] args) { GrailsApp.run(Application, args) } @Override void run(final String... args) throws Exception { println "Running in ${Environment.current.name}" // Get configuration from Holders. def config = Holders.getConfig() def locations = config.grails.config.locations locations.each { String configFileName = it.split("file:")[1] File configFile = new File(configFileName) if (configFile.exists()) { config.merge(new ConfigSlurper(Environment.current.name).parse(configFile.text)) } } } } 
0
source

All Articles