3

我有以下conf文件:

connection.port = 8080
connection.interface = "127.0.0.1"

阅读此文件时,我正在尝试使用提炼和提炼的纯配置。我有以下课程:

import com.api.models.{Config, Connection}
import com.typesafe.config.ConfigFactory
import pureconfig.error.ConfigReaderFailures
import pureconfig.loadConfig

object Configuration {
  val config = ConfigFactory.load()

  val stuff: Either[ConfigReaderFailures, Connection] = loadConfig[Connection](config)



 stuff match {
   case Left(left) => println(left)
   case Right(right) => println(right)
 }
}

这是阅读以下案例类:

case class Connection(port: Int, interface: String)

但是,当我尝试编译它时,出现以下错误:

Error:(19, 79) could not find implicit value for parameter reader: pureconfig.Derivation[pureconfig.ConfigReader[com.api.models.Connection]]
  val stuff: Either[ConfigReaderFailures, Connection] = loadConfig[Connection](config)

我真的不确定如何创建这样的隐含?

4

1 回答 1

1

Most likely you're missing an import probably this one: import pureconfig.generic.auto._

see https://pureconfig.github.io/docs/

If you're interested in what's happening here you can look into "typeclass derivation"

EDIT: Note that right now this has nothing to do with refined types as your code snipped is not using them.

于 2018-11-05T15:26:35.440 回答