Play Framework 2.1-RC2: NoSuchFieldError created by reverse routing in templates

I am working on a Java Play 2.1-RC2 application with MongoDB as a data warehouse. I am using the Jongo module to work with MongoDB. Everything went well until I got these errors:

java.lang.NoSuchFieldError: Home

These errors come from my patterns and are caused by using reverse routing. In this particular case, I'm trying to get to my Home controller.

The return route is as follows: @ routes.Home.edit (document.url)

and the route itself: GET / homepage /: url / edit controllers.Home.edit (url)

This worked before then, but started to give these errors since I started working on the MongoDB implementation. I can’t understand what the connection between the two will be. I do not think that I am somehow interfering with routing. This project started as project 2.0.4. The migration to 2.1-RC1 went well, and it seems that 2.1-RC2 still worked. I created my own class of the Model class to work with Mongo models. Could there be anything that causes this behavior?

@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; } } 

My .sbt plugins:

 // 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") 

My build.properties properties:

 sbt.version=0.12.2-RC2 

My 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") ) ) ) } 

The only application.conf lines that might matter are:

 playjongo.uri="mongodb://127.0.0.1:27017/test" playjongo.gridfs.enabled=false ehcacheplugin=enabled 

And stacktrace:

 ! @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] 

If anyone could tell me where these errors might come from or point me in the right direction, I would be very grateful! If you need more information, please let me know!

+4
source share
3 answers

Ok, I had the same error with Play 2.1.0, and after two nights spent on it, it looks like I finally found where the problem is!

In the module that I used, there was a controller called controllers.Application with its route filled with the module's conf / routes file, and I have the same controller in my project (also with a route). It seems like this was the source of the problem for me.

So, look in your modules (or subprojects?) For conflicting controllers or routes, and it should fix your problem.

+2
source

You should add a parameter type to the route. Therefore, it should be:

  GET /homepage/:url/edit controllers.Home.edit(url: String) 

There are several examples in the Play documentation that do not. But I believe declisit type is best practice.

0
source

https://github.com/hongsw/play2-JongoModel

I made a sample project for JongoModel

(Play! Framework 2.1)

0
source

All Articles