我正在使用MongoDB作爲數據存儲的Java Play 2.1-RC2應用程序。我正在使用Jongo模塊來處理MongoDB。 所有進行得很順利,直到我得到這樣的錯誤:Play Framework 2.1-RC2:通過模板中的反向路由創建NoSuchFieldError
java.lang.NoSuchFieldError的位置:首頁
這些錯誤從我的模板生成,並通過反向路由造成的。在這種特殊情況下,我試圖訪問我的主控制器。
反向路線是這樣的: @ routes.Home.edit(document.url)
像這樣的路線本身: GET /主頁/:URL /編輯controllers.Home.edit(URL )
以前有效,但是自從我開始研究MongoDB實現以來就開始出現這些錯誤。我無法弄清楚兩者之間的聯繫。我不認爲我以任何方式干擾路由。 該項目作爲2.0.4項目開始。移植到2.1-RC1進展良好,並且2.1-RC2似乎也一直工作,直到現在。我已經創建了自己的模型便利課程,用於使用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;
}
}
我plugins.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]
如果有誰能夠告訴我在哪裏,這些錯誤可能來自現身或點我在正確的方向我將不勝感激!如果您需要更多信息,請讓我知道!
我面臨同樣的問題。我注意到,當我使用'play start'命令時,應用程序可以正常工作。 –
非常感謝!事實上,當使用啓動命令我的應用程序再次運行!這是一個很奇怪的問題,但至少我可以繼續開發!任何想法可能會造成這種情況? –
Hi @DennisV。和@ biesior這方面的進展?你可以用'play run'工作嗎?我有完全相同的問題,它非常令人沮喪! – monsieurBelbo