我有以下 application.conf 文件:
# App
tables = [
"table_1",
"talbe_2"
]
和以下scala代码:
import pureconfig._
import pureconfig.generic.auto._
import com.typesafe.config.ConfigFactory
import pureconfig.generic.ProductHint
case class Configuration(tables: Array[String])
object Config {
implicit def hint[A] = ProductHint[A](ConfigFieldMapping(CamelCase, CamelCase))
val conf = ConfigSource.fromConfig(ConfigFactory.load("application.conf")).load[Configuration] match {
case Right(conf) => conf
case Left(failures) => throw new Exception(s"Unable to load the configuration ${failures.toList.mkString("\n")}")
}
}
并测试application.conf,我有这个代码:
object Test extends App {
val res = Config.conf.tables
println("hello")
}
当我将 application.conf 放在资源文件夹中时,它可以工作。但是当我使用它时它不起作用
-Dconfig.file=C:/Users/path/to/application.conf
尽管参数 -Dconfig.file 中有一个,但它使用资源 application.conf 文件。你有什么主意吗?