我正在开发一个使用 MongoDB 作为数据存储的 Java Play 2.1-RC2 应用程序。我正在使用 Jongo 模块来处理 MongoDB。一切都很顺利,直到我遇到这些错误:
java.lang.NoSuchFieldError: 主页
这些错误源自我的模板,是由使用反向路由引起的。在这种特殊情况下,我试图访问我的 Home 控制器。
反向路由如下所示:@routes.Home.edit(document.url)
路线本身是这样的: GET /homepage/:url/edit controllers.Home.edit(url)
这以前有效,但自从我开始研究 MongoDB 实现以来就开始出现这些错误。我想不通这两者之间有什么联系。我认为我不会以任何方式干扰路由。这个项目从 2.0.4 项目开始。迁移到 2.1-RC1 很顺利,而且 2.1-RC2 似乎也能正常工作,直到现在。我创建了自己的 Model 便利类来处理 Mongo 模型。那里有什么东西会导致这种行为吗?
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "_class")
public class Model {
@JsonProperty("_id")
public ObjectId id;
public MongoCollection models() {
String collectionName = this.getClass().getName() + "s";
return PlayJongo.getCollection(collectionName);
}
public void save() {
models().save(this);
}
public void update() {
this.remove();
this.save();
}
public void remove() {
models().remove(this.id);
}
public static class Finder<T> {
private final Class<T> type;
public Finder(Class<T> type) {
this.type = type;
}
public MongoCollection models() {
String collectionName = type.getName() + "s";
return PlayJongo.getCollection(collectionName);
}
public List<T> all() {
List<T> list = new ArrayList<>();
Iterator<T> it = models().find().as(type).iterator();
while (it.hasNext()) {
list.add(it.next());
}
return list;
}
public T byId(ObjectId id) {
return models().findOne(id).as(type);
}
public T byUrl(String url) {
return models().findOne("{url: #}", url).as(type);
}
public List<T> byQuery(String query) {
List<T> list = new ArrayList<>();
Iterator<T> it = models().find(query).as(type).iterator();
while (it.hasNext()) {
list.add(it.next());
}
return list;
}
}
我的插件.sbt:
// Comment to get more information during initialization
logLevel := Level.Warn
// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
// Use the Play sbt plugin for Play projects
addSbtPlugin("play" % "sbt-plugin" % "2.1-RC2")
我的 build.properties:
sbt.version=0.12.2-RC2
我的 Build.scala:
import sbt._
import Keys._
import play.Project._
object ApplicationBuild extends Build {
val appName = "Test"
val appVersion = "0.1-SNAPSHOT"
val appDependencies = Seq(
javaCore,
"uk.co.panaxiom" %% "play-jongo" % "0.3"
)
val main = play.Project(appName, appVersion, appDependencies).settings(
lessEntryPoints <<= (sourceDirectory in Compile)(base => (
(base / "assets" / "css" / "bootstrap.less") +++
(base / "assets" / "css" / "responsive.less")
)
)
)
}
唯一可能相关的 application.conf 行:
playjongo.uri="mongodb://127.0.0.1:27017/test"
playjongo.gridfs.enabled=false
ehcacheplugin=enabled
和堆栈跟踪:
! @6d48738mo - Internal server error, for (GET) [/] ->
play.api.Application$$anon$1: Execution exception[[RuntimeException: java.lang.NoSuchFieldError: Home]]
at play.api.Application$class.handleError(Application.scala:289) ~[play_2.10.jar:2.1-RC2]
at play.api.DefaultApplication.handleError(Application.scala:383) [play_2.10.jar:2.1-RC2]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$handle$1.apply(PlayDefaultUpstreamHandler.scala:114) [play_2.10.jar:2.1-RC2]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$handle$1.apply(PlayDefaultUpstreamHandler.scala:110) [play_2.10.jar:2.1-RC2]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1-RC2]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1-RC2]
java.lang.RuntimeException: java.lang.NoSuchFieldError: Home
at play.libs.F$Promise$6.apply(F.java:377) ~[play_2.10.jar:2.1-RC2]
at scala.concurrent.Future$$anonfun$map$1.liftedTree2$1(Future.scala:253) ~[scala-library.jar:na]
at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:249) ~[scala-library.jar:na]
at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:249) ~[scala-library.jar:na]
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:29) ~[scala-library.jar:na]
at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.liftedTree1$1(BatchingExecutor.scala:67) ~[akka-actor_2.10.jar:na]
Caused by: java.lang.NoSuchFieldError: Home
at views.html.documents.homepage$.apply(homepage.template.scala:45) ~[na:na]
at views.html.documents.homepage$.render(homepage.template.scala:51) ~[na:na]
at views.html.documents.homepage.render(homepage.template.scala) ~[na:na]
at controllers.Home.read(Home.java:24) ~[na:na]
at controllers.Application.index(Application.java:24) ~[na:na]
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$17$$anonfun$apply$17.apply(routes_routing.scala:251) ~[na:na]
如果有人能告诉我这些错误可能来自哪里或指出我正确的方向,我将不胜感激!如果您需要更多信息,请告诉我!