NotMyName
NotMyName

Reputation: 692

Controller issue when creating new Play application with Intellij 15

I created a new Play application with Intellij 15. The play version used was 2.4.2 so I updated it to 2.4.6 following the migration guide. I changed my Application controller to a Java class, but now I'm getting the following error:

Class 'Application' must either be declared abstract or implement abstract method 'RequestTimeout()' in 'Controller'

Here is what my application controller looks like:

package controllers;

import play.api.mvc.Controller;
import play.api.mvc.Result;

public class Application extends Controller {
    public Result index() {
        return ok(views.html.index("Your new application is ready."));
    }
}

I did add the routes generator (routesGenerator := InjectedRoutesGenerator) to my build.sbt as suggested in the Dependency Injection section of the migration guide.

Some final notes:

(1) I created the application as a Scala Play application because IntelliJ did not generate the project correctly when I tried creating it as a Java application with the Play framework, and I want to use sbt anyways.

(2) I noticed that the Scala Application controller was generated as an object rather than a class, indicating that it was still using static routes; so I'm guessing it has something to do with the dependency injection, but I don't see anything in their documentation other than the steps in the migration guide.

Any idea what I'm missing?

Upvotes: 0

Views: 336

Answers (1)

marcospereira
marcospereira

Reputation: 12214

You need to use play.mvc.Controller instead. In other words, don't use the api packages because they are intended to be used only in scala projects. Just change your code to:

package controllers;

import play.mvc.Controller; // no .api.
import play.mvc.Result; // no .api.

public class Application extends Controller {
    public Result index() {
        return ok(views.html.index("Your new application is ready."));
    }
}

About your notes:

  1. Use Activator to create projects and then import them to IDEA.

  2. Activator will probably create the project using DI instead of object to define controllers. Anyway, the steps at the migration guide suffice to migrate your app.

Upvotes: 0

Related Questions