I'm not quite sure what you mean by "we write our dataSources". You can probably do the same with Grails.
Anyway, if you want to be able to use the same WAR file in different environments, then Grails environments won't really help. One common approach if you're using Tomcat is to add these lines to your grails-app/conf/Config.groovy file:
Code:
grails.config.locations = [ "file:./${appName}-config.groovy", "classpath:${appName}-config.groovy" ]
So if your application has the name 'my-app', you can put a file called 'my-app-config.groovy' into Tomcat's 'lib' directory. This will override any settings in Config.groovy and DataSource.groovy. For example, I have this in a local 'site-config.groovy' file:
Code:
environments {
development {
dataSource.url = "jdbc:mysql://localhost/grails_org_new"
dataSource.driverClassName = "com.mysql.jdbc.Driver"
dataSource.username = "root"
dataSource.password = ""
dataSource.jndiName = null
dataSource.dbCreate = "create-drop"
}
...
}
An alternative approach is to put code into DataSource.groovy that evaluates the connection settings at runtime, via system properties or some other mechansim:
Code:
environments {
development {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop','update'
url = System.getProperty("JDBC_CONNECTION_STRING")
driverClassName = System.getProperty("JDBC_DRIVER_CLASS")
username = System.getProperty("JDBC_USERNAME")
password = System.getProperty("JDBC_PASSWORD")
}
}
...
}
You don't have to use system properties. Almost any code would be valid.