19.5 Property Placeholder Configuration - Reference Documentation
Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith, Lari Hotari
Version: 3.1.9
19.5 Property Placeholder Configuration
Grails supports the notion of property placeholder configuration through an extended version of Spring's PropertyPlaceholderConfigurer.Settings defined in either ConfigSlurper scripts or Java properties files can be used as placeholder values for Spring configuration ingrails-app/conf/spring/resources.xml
and grails-app/conf/spring/resources.groovy
. For example given the following entries in grails-app/conf/application.groovy
(or an externalized config):database.driver="com.mysql.jdbc.Driver" database.dbname="mysql:mydb"
resources.xml
as follows using the familiar ${..} syntax:<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"> <value>${database.driver}</value> </property> <property name="url"> <value>jdbc:${database.dbname}</value> </property> </bean>
resources.groovy
you need to use single quotes:dataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) { driverClassName = '${database.driver}' url = 'jdbc:${database.dbname}' }
resources.groovy
is to access properties through the grailsApplication
variable:dataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) {
driverClassName = grailsApplication.config.database.driver
url = "jdbc:${grailsApplication.config.database.dbname}"
}