1

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
    }
}
}
  • That doesn't make a lot of sense - the return type of `getProperty` is `String`. Does it work now if you remove `as String`? My guess is you needed to force a recompile and any no-op change like this would have done the trick. – Burt Beckwith Feb 18 '15 at 01:38
  • Cleaned followed by recompile numerous times. Started the project from scratch from versions of grails from 2.3.6 to 2.4.4. As soon as I tried any version of grails 2.4.1 and above default values were returned. An assignment of username = "explicit string" works on 2.4.x, not username = System.getProperty(). – Shane MacPhillamy Feb 18 '15 at 01:50

0 Answers0