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.
精彩评论