我正在尝试从 Scala 中的配置源传递持续时间变量。我尝试了很多不同的参数。但我每次都收到错误。
scalaVersion := "2.13.4"
import pureconfig.ConfigSource
import scala.concurrent.duration.Duration
...
case class KafkaConfig(bootstrapServers: String, batchSize: Int, batchInterval: Duration)
...
val AppConfig(kafkaConfig) = ConfigSource.default.loadOrThrow[AppConfig]
我的 application.conf 看起来像:
kafka {
bootstrap-servers="localhost:9092",
batch-size=1000,
batch-interval = ${BATCH_INTERVAL}
}
无论我为 ${BATCH_INTERVAL} 变量尝试了什么,我都会收到如下错误:“1)找不到密钥:'batch-ıinterval'。”
我试过了:
batch-interval=5
batch-interval=5.millis
batch-interval=Duration(5, "millis")
batch-interval=Duration(5, MILLISECONDS)
我真的不知道该怎么办。有什么建议么?