开发者

Cake Pattern and Spring Configurer

Spring provides utility Configurer to resolve placeholders with external configuration data (see the documentation for details). How can I configure my components in a similar way (that is, using external configuration to resolve 开发者_运维知识库placeholders) with Cake Pattern?

For example:

 // properties configuration file

driver=com.mysql.jdbc.Driver
dbname=mysql:mydb
user=michael
password=*****

trait JdbcSupport {
  val dataSource:Datasource
  ...
}

trait OrderDAOComponent {self: JdbcSupport =>
  val dao: OrderDAO
  class OrderDAOImpl extends OrderDAO {...} // use the JDBC data source here
}

How can I use the properties configuration file to initialize the OrderDAO using the Cake Pattern?


trait XmlConfigJdbcSupport extends JdbcSupport {
  val xmlFile:String
  override val dataSource = readConfigAndReturnDatasource()
}

object MyContext extends OrderDAOComponent with XmlConfigJdbcSupport {
  override val xmlFile = "config.xml"
}

dataSource should probably be a lazy val to avoid problems with the initialization order.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜