I run grails applications in AWS Elastic Beanstalk; I pass DB authentication credentials via command line parameters and retrieve them via System.getProperty(). In DataSource.groovy for grails 2.3.x, the following worked:
environments {
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
driverClassName = "org.postgresql.Driver"
dialect = "net.kaleidos.hibernate.PostgresqlExtensionsDialect"
url = System.getProperty("JDBC_CONNECTION_STRING")
username = System.getProperty("PARAM1")
password = System.getProperty("PARAM2")
}
}
}
With grails 2.4.x when the fields url, username and password are evaluated by the PostgreSQL driver the default values are returned not the result of evaluating the System.getProperty() method. An explicit cast with as String seems to remedy the situation.
environments {
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
driverClassName = "org.postgresql.Driver"
dialect = "net.kaleidos.hibernate.PostgresqlExtensionsDialect"
url = System.getProperty("JDBC_CONNECTION_STRING") as String
username = System.getProperty("PARAM1") as String
password = System.getProperty("PARAM2") as String
}
}
}