我正在将PureConfig与Refined一起使用。我有以下案例课:
case class Config(port: ServerPort, interface: String)
ServerPort是我使用Refined定义的自定义类型。我正在使用pureconfig将conf文件加载到Config case类中,如下所示:
import com.api.models.Config
import com.typesafe.config.ConfigFactory
import eu.timepit.refined.W
import eu.timepit.refined.api.Refined
import eu.timepit.refined.auto._
import eu.timepit.refined.numeric.Greater
import pureconfig.{ConfigReader, loadConfig}
object Configuration {
type ServerPort = Int Refined Greater[W.`1024`.T]
val port = 8080
val interface = " 127.0.0.1"
val config = ConfigFactory.load()
val connection: Config = loadConfig[Config](config,"connection").getOrElse(Config(8080,"127.0.0.1"))
}
但是,每当我运行此命令时,都会出现以下错误:
Error:(21, 37) could not find a ConfigReader instance for type Config
implicit val reader = ConfigReader[Config].map(item => new Config(item.port,item.interface))
有没有一种方法可以使用pureconfig读取自定义类型?