在参考https://github.com/AhmadMelegy/play-silhouette-reactivemongo-angular-seed编译时从ReactiveMongo.0.11.1到ReactiveMongo 0.12.0的重构失败:
def configure() {
bind[DB].toInstance
{
import com.typesafe.config.ConfigFactory
import reactivemongo.api.DefaultDB
import scala.concurrent.ExecutionContext.Implicits.global
import scala.collection.JavaConversions._
import scala.concurrent.Future
val config = ConfigFactory.load
val driver = new MongoDriver
val connection = driver.connection(
config.getStringList("mongodb.servers"),
MongoConnectionOptions(),
Seq()
)
connection.database(config.getString("mongodb.db"))
}
如何解决此问题?
required: reactivemongo.api.DB
found : scala.concurrent.Future[reactivemongo.api.DefaultDB]
答案 0 :(得分:0)
不推荐
您可以使用Await
接收Future
的结果并绑定它。
<强>推荐强>
使用“play.modules.reactivemongo.ReactiveMongoModule” http://reactivemongo.org/releases/0.12/documentation/tutorial/play.html
配置示例:
# The default URI
mongodb.uri = "mongodb://someuser:somepasswd@localhost:27017/foo"
# Another one, named with 'bar'
mongodb.bar.uri = "mongodb://someuser:somepasswd@localhost:27017/lorem"
代码示例
class MyComponent @Inject() (
val defaultApi: ReactiveMongoApi, // corresponds to 'mongodb.uri'
@NamedDatabase("bar") val barApi: ReactiveMongoApi // 'mongodb.bar'
) {
}
如果你需要自己绑定,那么只需看看这个例子: https://github.com/ReactiveMongo/Play-ReactiveMongo/blob/master/src/main/scala/play/modules/reactivemongo/ReactiveMongoModule.scala