You received this message because you are subscribed to a topic in the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/grails-dev-discuss/_5VtFz4SpDY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to grails-dev-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/CAO_wNodw9bFZ92aKm6rEtaxDup-tj%2BUZoKHHMvBhyTCqrSCMPA%40mail.gmail.com.
import grails.util.Environment...
switch (Environment.current) { case Environment.DEVELOPMENT: configureForDevelopment() break case Environment.PRODUCTION: configureForProduction() break }
class Application extends GrailsAutoConfiguration implements EnvironmentAware {
static void main(String[] args) {
GrailsApp.run(Application)
}
@Override
void setEnvironment(Environment environment) {
String configPath = System.properties["appname.config.location"]
Resource resourceConfig = new FileSystemResource(configPath);
YamlPropertiesFactoryBean ypfb = new YamlPropertiesFactoryBean();
ypfb.setResources(resourceConfig);
ypfb.afterPropertiesSet();
Properties properties = ypfb.getObject();
environment.propertySources.addFirst(new PropertiesPropertySource("appname.config.location", properties))
}
}
build.gradle
bootRun {
jvmArgs = ['-Dappname.config.location=/path/to/config.yml']
}
import org.springframework.core.env.Environment
import grails.boot.config.GrailsAutoConfiguration
import org.springframework.core.env.MapPropertySource
class ApplicationConfigurationLoader {
private ApplicationConfigurationLoader() {}
public static load(GrailsAutoConfiguration application, Environment environment) {
if (application && environment) {
DefaultResourceLocator resourceLocator = new DefaultResourceLocator()
def applicationGroovy = application.getClass().classLoader.getResource('application.groovy')
if (applicationGroovy) {
def applicationConfiguration = new ConfigSlurper(grails.util.Environment.current.name).parse(applicationGroovy)
for (String configLocation in applicationConfiguration.grails.config.locations) {
def configurationResource = resourceLocator.findResourceForURI(configLocation)
if (configurationResource) {
def config = new ConfigSlurper(grails.util.Environment.current.name).parse(configurationResource.getURL())
environment.propertySources.addFirst(new MapPropertySource(configLocation, config))
}
}
}
}
}
}
@Override
void setEnvironment(Environment environment) {
ApplicationConfigurationLoader.load(this, environment)
}