适用于Scala的Play框架:[类型BooksController不是包控制器的成员]

时间:2018-12-06 12:18:44

标签: java scala playframework playframework-2.0

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

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

而BooksController是

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 个答案:

答案 0 :(得分:1)

这可能是因为您的控制器是Java类而不是Scala类。我知道我自己弄错了,把它混在一起。

我正在特别考虑,因为您得到了以下提示:Compiling 4 Scala sources and 1 Java source,也许包装是不正确的。也许应该更容易/app/controllers来检查您的想法。