第四話(??):易於重構的配置方案
某男神四年前做的一個項目:
zhongl/config-annotation依然是最酷炫的通用的Scala項目配置方案。
昨天在
sadhen/spring-booted-scala
針對Spring Boot做了一些適配。暫時能夠Running,但遠遠沒有到State of Art。
主要有以下三大優點:
易於重構
// Spring Boot自帶功能
@Value("${crontab.task1.expr}")
private var cronExpr: String = _
// Config Annotation的黑魔法
class XYZService extends crontab {
val cronExpr = task1.expr
}
@conf
trait crontab {
val task1 = new {
val expr = "*/10 * * * * *"
val action = "laugh"
val desc = "every ten seconds"
}
val task2 = new {
val fixed = new {
val delay = (1 second).toMillis.toString
val rate = (3 seconds).toMillis.toString
}
val action = "blink"
val desc = "every three seconds"
}
}
Typesafe Config 真的 Typesafe 麼?
Typesafe你妹,明明是Lightbend Config。
配置的可讀性:1000為什麼是1s?
因為`(1 second).toMillis`就是1000啊。
推薦閱讀: