Skip to content
This repository has been archived by the owner on Apr 14, 2022. It is now read-only.

Reading application properties #29

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

wodzuu
Copy link
Contributor

@wodzuu wodzuu commented Aug 11, 2013

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.

ramnivas and others added 6 commits August 1, 2013 20:01
RestTemplate consisted of methods of the following form (getFor..., postFor..., etc.)
    def m(...)
and
    def m(..., uriVariables: Any*)

This made it impossible to call methods without passing any uriVariables, since the compiler cannot determine which of the overloaded method is intended. In any case, there is no need for the non-varargs methods; users can just call the varargs version passing no arguments for the uriVariables parameter.
Added TransactionSupport trait that can be used to extend
FunctionalConfiguration. enableTransactionManagement(...) function is
equivalent to traditional <tx:annotation-driven ...>.
PropertiesResolver - to ease access to application properties when
configuring Spring beans
PropertiesAware - to ease access to application properties from the
Spring beans
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants