SpringSource/spring-scala — pull request #29 by wodzuu (2013-08-11 21:08:03+00:00)
Title: Reading application properties

Hi,

I have thought about creating some mechanism to simplify access to application properties inside classes extending `FunctionalConfiguration`. Therefore I have created `PropertiesResolver` trait that introduces variable `$` which can be used to access them in two ways: `$("my.property.name")` or `$.my.property.name`. This does not define properties source in any way, but just creates simple mechanism of accessing them.

Sample usage:

class Config extends FunctionalConfiguration with PropertiesResolver {
bean("propertiesConfig") {
new PropertyPlaceholderConfigurer { ...}
}

val dataSource = bean("dataSource") {
val dataSource = new BasicDataSource()
dataSource.setDriverClassName($.database.driver.class)
dataSource.setUrl($.database.url)
dataSource.setUsername($.database.username)
dataSource
} destroy {
_.close()
}
}

I have also created another trait `PropertiesAware` that, when extended by any bean, gives it access to properties the same way:

class SomeBean extends PropertiesAware {
lazy val version:String = $.app.version
lazy val revision:Int = $.app.revision.toInt
lazy val debugMode:Boolean = $.debug.toBoolean
}

For those more used to referencing properties by String `$("app.version")` is also available and of course good old `@Value("${app.version}")` works too.

Let me know what do you think.