Play Framework 路由器找不到 Java 方法
Play Framework router won't find Java method
我在 IntelliJ 上创建了一个 Play Framework 2 项目。这是我的路线文件:
# Home page
GET / controllers.Application.index()
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
这是我的申请 class:
package controllers;
import play.mvc.Controller;
import play.mvc.Result;
import views.html.index;
public class Application extends Controller {
public Result index() {
return ok(index.render("Your new application is ready."));
}
}
但是当我转到 localhost:9000 时出现此错误:
value index is not a member of object controllers.Application
我做错了什么?如果它有帮助,当我使用 scala classes.
时它确实可以正常工作
编辑:
这是我的 build.sbt 文件:
name := "products"
version := "1.0"
lazy val `products` = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.7"
libraryDependencies ++= Seq( jdbc , cache , ws , specs2 % Test )
unmanagedResourceDirectories in Test <+= baseDirectory ( _ /"target/web/public/test" )
resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases"
我注意到我只启用了 PlayScala 插件,所以我将其更改为 PlayJava
lazy val `products` = (project in file(".")).enablePlugins(PlayJava)
但我仍然遇到同样的错误。
原来我使用的是旧版本的 Play Framework
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.2")
那只允许静态方法作为路由。我所做的是更改为这个版本的 Play Framework
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.6")
这确实允许并实际上强制执行非静态方法作为路由处理程序。
我在 IntelliJ 上创建了一个 Play Framework 2 项目。这是我的路线文件:
# Home page
GET / controllers.Application.index()
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
这是我的申请 class:
package controllers;
import play.mvc.Controller;
import play.mvc.Result;
import views.html.index;
public class Application extends Controller {
public Result index() {
return ok(index.render("Your new application is ready."));
}
}
但是当我转到 localhost:9000 时出现此错误:
value index is not a member of object controllers.Application
我做错了什么?如果它有帮助,当我使用 scala classes.
时它确实可以正常工作编辑:
这是我的 build.sbt 文件:
name := "products"
version := "1.0"
lazy val `products` = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.7"
libraryDependencies ++= Seq( jdbc , cache , ws , specs2 % Test )
unmanagedResourceDirectories in Test <+= baseDirectory ( _ /"target/web/public/test" )
resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases"
我注意到我只启用了 PlayScala 插件,所以我将其更改为 PlayJava
lazy val `products` = (project in file(".")).enablePlugins(PlayJava)
但我仍然遇到同样的错误。
原来我使用的是旧版本的 Play Framework
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.2")
那只允许静态方法作为路由。我所做的是更改为这个版本的 Play Framework
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.6")
这确实允许并实际上强制执行非静态方法作为路由处理程序。