How to install ReactiveMongo in game 2.4?

I installed the following: 1.Plate 2.4 2.Created a scala project 3. Added eclipse plugin

Now I wanted to add a database connection. I want to try ReactiveMongo, but the instructions on the wiki page are for 2.3 or older.

https://github.com/ReactiveMongo/Play-ReactiveMongo

For 2.4, it seems that the file structure of the game has changed. I need to know the correct way to configure play 2.4 for ReactiveMongo.

Here are the instructions they give for game versions, but no more than 2.4:

If you want to use the latest snapshot, add the following instead (only for play > 2.3): resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/" libraryDependencies ++= Seq( "org.reactivemongo" %% "play2-reactivemongo" % "0.11.0-SNAPSHOT" ) Configure your application to use ReactiveMongo plugin add to your conf/play.plugins 1100:play.modules.reactivemongo.ReactiveMongoPlugin Configure your database access within application.conf 

How do I apply this configuration to the new 2.4 playback file structure?

This is what I tried to do without success: In the /plugins.sbt project, I added:

 resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/" addSbtPlugin("org.reactivemongo" % "play2-reactivemongo" % "0.11.0-SNAPSHOT") 

I get a permission error message:

  at java.lang.Thread.run(Thread.java:745) [error] (*:update) sbt.ResolveException: unresolved dependency: org.reactivemong o#play2-reactivemongo;0.11.0-SNAPSHOT: not found 

So, after learning that I need to add a dependency to the /build.sbt file and made changes there.

 name := """oneid-scala""" version := "1.0-SNAPSHOT" lazy val root = (project in file(".")).enablePlugins(PlayScala) scalaVersion := "2.11.6" libraryDependencies ++= Seq( jdbc, cache, ws, specs2 % Test ) resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases" //This is for reactivemongodb resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/" //This is for reactivemongodb libraryDependencies ++= Seq( "org.reactivemongo" %% "play2-reactivemongo" % "0.11.0-SNAPSHOT" ) // Play provides two styles of routers, one expects its actions to be injected, the // other, legacy style, accesses its actions statically. routesGenerator := InjectedRoutesGenerator EclipseKeys.createSrc := EclipseCreateSrc.All 

After completing these steps, I want to verify that the installation is correct. So I tried to add the tutorial code to my project from https://github.com/ReactiveMongo/Play-ReactiveMongo

 /app /controllers/Application.scala /controllers/UsingJsonReadersWriters.scala /models/models.scala /conf /routes 

Then I activate the activator. Then I launch the activator.

I see an error after starting:

 missing or invalid dependency detected while loading class file 'JSONGenericHandlers.class'. Could not access type GenericHandlers in package reactivemongo.api.collections, because it (or its dependencies) are missing. Check your build definition for missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.) A full rebuild may help if 'JSONGenericHandlers.class' was compiled against an incompatible version of reactivemongo.api.collections. 

So, it seems that my installation failed. So this question is still open.

+6
source share
2 answers

Add the following line to build.sbt :

 "org.reactivemongo" %% "play2-reactivemongo" % "0.11.0.play24" 

eg:

 libraryDependencies ++= Seq( jdbc, cache, ws, specs2 % Test, "org.reactivemongo" %% "play2-reactivemongo" % "0.11.0.play24", "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test" ) 

As for examples of reactive mongo, I never made them work. I think they might be a bit dated. Try it (not the best example, but simple):

 import reactivemongo.api.MongoDriver import reactivemongo.api.collections.bson.BSONCollection import reactivemongo.bson.BSONDocument import scala.concurrent.Await import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.duration._ class RMongoTest(){ def run = { val dbHosts: List[String] = List("localhost") val dbName = "TestDB" val driver = new MongoDriver val connection = driver.connection(dbHosts) val db = connection("TestDB") val collection :BSONCollection = db("TestCollection") val futureInsert = collection.insert(BSONDocument("Moo" -> "Over")) Await.result(futureInsert, 10.seconds) //Not really a great pattern... val futureResult = collection.find(BSONDocument()).one val result = Await.result(futureResult, 10.seconds) println(result.get.get("Moo")) } } 
+1
source

If someone is still looking for answers: in Play 2.4.x, the dependency added to your build.sbt looks like this:

For ReactiveMongo 0.11.7 :

 libraryDependencies ++= Seq( // ... "org.reactivemongo" %% "play2-reactivemongo" % "0.11.7.play24" ) 

For ReactiveMongo 0.11.9 (released December 20, 2015):

 scalaVersion := "2.11.7" libraryDependencies ++= Seq( // ... "org.reactivemongo" % "play2-reactivemongo_2.11" % "0.11.9" // Or to let SBT add the Scala version suffix automatically: "org.reactivemongo" %% "play2-reactivemongo" % "0.11.9" ) 

Note that from time to time, it seems that the naming time changes. For future releases, you can try the following steps:

  • Go to the Maven Central repository and search for g:"org.reactivemongo" play .
  • Find the ArtifactId that ends with roughly your version of Scala, for example. play2-reactivemongo_2.11 if you have Scala 2.11.x
  • Click on the version number (e.g. 0.11.9 ) in this line, which will bring you to a page, such as this .
  • In the Dependency Information section, click Scala SBT.
  • Copy the line to the build.sbt file. If you have a libraryDependencies ++= Seq(...) section, copy only the part after += .
0
source

Source: https://habr.com/ru/post/988200/


All Articles