我正在我的scala项目中使用连线。我有个usecase --
class SchemaRegistry(registry: SchemaRegistryClient)
class SchemaRegistryClient(url: String) extends RestService(url) {}
trait EndpointModule {
// Schema Registry endpoint dependency
lazy val schemaRegistry: SchemaRegistry = wire[SchemaRegistry]
def schemaRegistryClient(url: String): SchemaRegistryClient = wire[SchemaRegistryClient]
}
object LightweightinstructionRunner extends EndpointModule with ConfigModule {
val client = schemaRegistryClient("")
}这会导致一个错误-
etl.infrastructure.endpoints.SchemaRegistryClient:
找不到类型的值
如果我在SchemaRegistryClient中创建硬编码的EndpointModule.对象,它就能工作。
(val c = new SchemaRegsitryClient(""))有人能帮助解释如何解决这个问题,以及这里发生了什么吗?
我似乎找不到一种方法来满足这种依赖。
LightweightinstructionRunner在一个diff包中,而SchemaRegistry和SchemaRegistryClient在同一个包中。
发布于 2020-05-24 12:34:58
要使用的SchemaRegistryClient必须在宏的范围内才能找到它。您可以在您的def中为它声明一个抽象的EndpointModule (没有任何参数,因为MacWire不知道在其中放哪个url )。
trait EndpointModule {
// Schema Registry endpoint dependency
def client: SchemaRegistryClient
lazy val schemaRegistry: SchemaRegistry = wire[SchemaRegistry]
}
object LightweightinstructionRunner extends EndpointModule with ConfigModule {
override val client = SchemaRegistryClient("")
}
// or maybe
class LightweightinstructionRunner(url: String) extends EndpointModule with ConfigModule {
override val client = SchemaRegistryClient(url)
}https://stackoverflow.com/questions/61985950
复制相似问题