有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Scala的java Play Framework:[类型控制器不是包控制器的成员]

我尝试编译,但在控制台上出现以下编译错误

<&燃气轮机@7a6b9ggi8-内部服务器错误,用于(GET)[/books]->

 play.sbt.PlayExceptions$CompilationException: Compilation error[type BooksController is not a member of package controllers]
    at play.sbt.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27)
    at play.sbt.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27)
    at scala.Option.map(Option.scala:145)
    at play.sbt.run.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:49)
    at play.sbt.run.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:44)
    at scala.Option.map(Option.scala:145)
    at play.sbt.run.PlayReload$.taskFailureHandler(PlayReload.scala:44)
    at play.sbt.run.PlayReload$.compileFailure(PlayReload.scala:40)
    at play.sbt.run.PlayReload$$anonfun$compile$1.apply(PlayReload.scala:17)
    at play.sbt.run.PlayReload$$anonfun$compile$1.apply(PlayReload.scala:17)
 [info] Compiling 4 Scala sources and 1 Java source to /Users/Play/PROJ_NAME/target/scala-2.11/classes...
 [error] /Users/Play/PROJ_NAME/conf/routes:18: type BooksController is not a member of package 

controllers
[error] GET     /books                      controllers.BooksController.index()
[error] /Users/Play/PROJ_NAME/conf/routes:18: type BooksController is not a member of package controllers
[error] GET     /books                      controllers.BooksController.index()
[error] /Users/Play/PROJ_NAME/conf/routes:18: type BooksController is not a member of package controllers
[error] GET     /books                      controllers.BooksController.index()
[error] three errors found
[error] (compile:compileIncremental) Compilation failed
[error] application -

控制器是

package controllers;

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

import play.*;
import play.data.*;
import play.mvc.*;
import views.html.*;
//
public class BooksController extends Controller{
    public Result index(){
        return TODO;
    }
}

路线是

GET     /                           controllers.HomeController.index
# An example controller showing how to use dependency injection
GET     /count                      controllers.CountController.count
# An example controller showing how to write asynchronous code
GET     /message                    controllers.AsyncController.message
# Map static resources from the /public folder to the /assets URL path
GET     /assets/*file               controllers.Assets.versioned(path="/public", file: Asset)

#フォーム処理アクション
#POST   /send                       controllers.HomeController.send()

#book用
GET     /books                      controllers.BooksController.index()
#GET     /books/create               controllers.BooksController.create()
#GET     /books/:id                  controllers.BooksController.show(id: Integer)
#GET     /books/edit/:id             controllers.BooksController.edit(id: Integer)
#POST    /books/edit                 controllers.BooksController.update()
#POST    /books/create               controllers.BooksController.save()
#GET     /books/delete/:id           controllers.BooksController.destroy(id: Integer)

GET     /about/

我正在使用Play Framework 2.5.10 如何调试此编译错误

谢谢你的支持


共 (1) 个答案

  1. # 1 楼答案

    这可能是因为控制器是java类而不是scala类。我知道我自己犯了一个错误,把它弄混了

    我在想,尤其是当你得到这个:Compiling 4 Scala sources and 1 Java source也许这个包是不正确的。也许它应该是/app/controllers也许你更容易签入你的ide