def homeDir = System.properties.getProperty('app.home');
if(homeDir){
// Using external configurations if home dir specified
grails.config.locations = ["file:${homeDir}/database.properties"]
}
Could you please tell me how to do this in grails 3 ?
It's really a pain to me to upgrade my tiny app to grails 3 as I have to learn spring-boot, spring-*-4.0 new concepts from scratch,
and struggle with the spring-boot WAR deployment with my existing tomcat server :(
Thanks,
Shawn
environments.development.dataSource.pooled=true
environments.development.dataSource.driverClassName=com.mysql.jdbc.Driver
environments.development.dataSource.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
environments.development.dataSource.url=jdbc:mysql://localhost/myappdb?useUnicode=yes&characterEncoding=UTF-8
environments.development.dataSource.username=foobar
environments.development.dataSource.password=secret
void setEnvironment(Environment env) { //ApplicationConfigurationLoader.load(this,env); //Set up Configuration directory def appHome = System.getenv('myapp.home') ?: System.getProperty('myapp.home') ?: "/opt/mclub" log.info "Loading configuration from ${appHome}" def dbcfgFile = new File(appHome, DATABASE_CONFIG_FILE); if (!dbcfgFile.exists()) { log.info(" configuration ${dbcfgFile} not found") return; } log.info(" configuration ${dbcfgFile} found") try{ Properties config = new Properties(); config.load(new FileInputStream(dbcfgFile)); Map<String,String> originalConfig = new HashMap<String,String>(config); env.activeProfiles?.each{ String activeProfileName-> log.info "Actionve profile: ${activeProfileName}" String keyPrefix = "environments." + activeProfileName + "."; // prefix all configurations with environment.${profile}. for(Map.Entry<String,String> e in originalConfig.entrySet()){ if(!(e.key.startsWith(keyPrefix))){ config.put(keyPrefix + e.key,e.value); } } }
ConfigurableEnvironment cenv = (ConfigurableEnvironment)env; cenv.propertySources.addFirst(new PropertiesPropertySource("external.datasource", config))
// TEST PART - I'M NEWBIE TO SPRING4! if(DUMP_CONFIG_ENABLED){ log.info("dump property sources - begins") cenv.getPropertySources().each{ PropertySource p -> log.info("${p.class} - ${p}"); if(p instanceof EnumerablePropertySource){ ((EnumerablePropertySource)p).propertyNames.each{ String pName -> log.info(" ${pName} -> ${p.getProperty(pName)}"); } }else{ log.info " not enumerable" } } log.info("dump property sources - completed") } }catch(Exception e){ log.error "Error loading DB configuration: ${e.message}", e } }
--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-disc...@googlegroups.com.
To post to this group, send email to grails-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/4686f541-a4cb-43d8-a7d3-c5015d819fd2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.