gpt4 book ai didi

scala - pureconfig 无需手动导入 pureconfig.generic.auto._

转载 作者:行者123 更新时间:2023-12-04 01:22:29 39 4
gpt4 key购买 nike

0.10.*pureconfig 的最新更新系列默认禁用自动配置。

import pureconfig.generic.auto._

需要手动导入。
但是我有一个类层次结构,我不想每次都为子类导入它。
import pureconfig.ConfigReader
abstract class SparkBaseRunner[T <: Product](implicit A: ConfigReader[T])extends App {}

已经需要一个 configReader。
使用此基类时:
object MyOperation extends SparkBaseRunner[MyCaseClass] {}

它失败了:
could not find implicit value for parameter A: pureconfig.ConfigReader[foo.bar.my.Type]

除非在每个子类中手动指定上述输入。有没有办法避免这种代码重复?尝试在抽象基类中指定输入对我来说不起作用,因为它已经需要一个 ConfigReader 对象。

编辑

尝试手动访问基类中的配置读取器也会失败:
implicit val configReader = deriveReader[T]
could not find implicit value for parameter A: pureconfig.ConfigReader[T]
could not find Lazy implicit value of type pureconfig.generic.DerivedConfigReader[T]

我的 Scala 版本是:2.11.12

最佳答案

我相信配置已经被作为单个操作读取,并且有多个应用程序,都在执行以下操作:

object Ops extends SparkBaseRunner[MyCaseClass]

我看不到避免重复的方法,因为基类无法推断配置,因为它只有一个泛型类型 T .

最好的解决办法是不用担心,使用 auto._ .
import pureconfig.generic.auto._

关于scala - pureconfig 无需手动导入 pureconfig.generic.auto._,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54919635/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com