找不到:来自注册表的值

时间:2019-05-09 19:04:43

标签: scala akka akka-stream alpakka

我正在尝试使用https://doc.akka.io/docs/alpakka/current/mongodb.html如下:

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import cats.data.Chain
import com.mongodb.reactivestreams.client.MongoClients
import org.mongodb.scala.bson.codecs.DEFAULT_CODEC_REGISTRY
import org.mongodb.scala.bson.codecs.Macros._

object Main extends App {
  implicit val system = ActorSystem()
  implicit val mat = ActorMaterializer()

  val preFailure = MsgPreFailure("Hello", Chain("Foo", "Too"))
  val codecRegistry = fromRegistries(fromProviders(classOf[MsgPreFailure]), DEFAULT_CODEC_REGISTRY)

  private val client = MongoClients.create("mongodb://localhost:27017")
  private val db = client.getDatabase("MongoSourceSpec")
  private val preFailureColl = db
    .getCollection("numbers", classOf[MsgPreFailure])
    .withCodecRegistry(codecRegistry)
} 

编译器抱怨:

[error] /home/developer/scala/trymongo/src/main/scala/Main.scala:15:23: not found: value fromRegistries
[error]   val codecRegistry = fromRegistries(fromProviders(classOf[MsgPreFailure]), DEFAULT_CODEC_REGISTRY)
[error]                       ^
[error] /home/developer/scala/trymongo/src/main/scala/Main.scala:15:38: not found: value fromProviders
[error]   val codecRegistry = fromRegistries(fromProviders(classOf[MsgPreFailure]), DEFAULT_CODEC_REGISTRY)
[error]                                      ^ 

我想念什么?该项目可以在这里https://gitlab.com/playscala/trymongo

中找到

1 个答案:

答案 0 :(得分:2)

我认为您可能需要导入它,请尝试导入:

import org.bson.codecs.configuration.CodecRegistries.{fromProviders, fromRegistries}