Tôi đã cài đặt như sau: 1.Play 2.4 2.Created một dự án scala 3.added nhật thực cắmLàm thế nào để cài đặt ReactiveMongo khi chơi 2.4?
Bây giờ tôi muốn thêm một kết nối cơ sở dữ liệu. Tôi muốn dùng thử ReactiveMongo, nhưng các hướng dẫn trên trang wiki là dành cho 2.3 trở lên.
https://github.com/ReactiveMongo/Play-ReactiveMongo
Đối với 2,4 có vẻ như cấu trúc tệp của trò chơi đã thay đổi. Tôi cần phải biết cách thích hợp để cấu hình chơi 2.4 cho ReactiveMongo.
Dưới đây là các hướng dẫn họ cung cấp cho các phiên bản chơi mới hơn 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
Làm thế nào tôi sẽ áp dụng có cấu hình để cấu trúc file mới chơi 2.4?
Đây là những gì tôi đã cố gắng để làm với không thành công: Trong dự án/plugins.sbt Tôi nói thêm:
resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
addSbtPlugin("org.reactivemongo" % "play2-reactivemongo" % "0.11.0-SNAPSHOT")
tôi nhận được một thông báo lỗi giải quyết:
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
Vì vậy, sau khi học rằng tôi cần thêm phụ thuộc vào tệp /build.sbt và thực hiện các thay đổi ở đó.
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
Sau khi thực hiện các bước này, tôi muốn xác minh xem tôi đã cài đặt đúng chưa. Vì vậy, tôi đã cố gắng để thêm mã hướng dẫn để dự án của tôi từ https://github.com/ReactiveMongo/Play-ReactiveMongo
/app
/controllers/Application.scala
/controllers/UsingJsonReadersWriters.scala
/models/models.scala
/conf
/routes
Sau đó, tôi làm một activator sạch Sau đó, tôi làm một chạy activator
tôi thấy một lỗi sau khi chạy:
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.
Vì vậy, có vẻ như cài đặt của tôi không thành công. Vì vậy, câu hỏi này vẫn còn mở.
Bạn có thể xem [tài liệu] (http://reactivemongo.org/releases/0.11.0/documentation/tutorial/play2.html) được cập nhật vì plugin đã có sẵn dưới dạng 0.11.0. play24-M2 (cột mốc sắp được phát hành là 0,11). – cchantep