Play Framework - 值login不是controllers.Application的成员

ste*_*pjm 2 java playframework

我正在运行最新的Play Framework 2.5.1,我从登录页面收到错误:

错误:

value login is not a member of controllers.Application
Run Code Online (Sandbox Code Playgroud)

我试过添加@符号即:

@controllers.Application.login()
Run Code Online (Sandbox Code Playgroud)

并从build.sbt"CMD"中清除/清理文件和更新中删除注射器.我正在使用https://www.playframework.com/documentation/2.1.0/JavaGuide中的示例.

HTML代码

@(form: Form[Application.Login])
<html>
    <head>
        <title>Zentasks</title>
        <link rel="shortcut icon" type="image/png" href="@routes.Assets.versioned("images/favicon.png")">
        <link rel="stylesheet" type="text/css" media="screen" href="@routes.Assets.versioned("stylesheets/login.css")">
    </head>
    <body>
        <header>
            <a href=@routes.Application.index" id="logo"><span>Zen</span>tasks</a>
        </header>

    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

CONTROLLERS

package controllers;

import play.*;
import play.mvc.*;

import views.html.*;

public class Application extends Controller {

    public Result index() {
        return ok(index.render("Your new application is ready."));
    }



    public static Result login() {
        return ok(
            login.render(form(Login.class))
        );
    }

    public static class Login {
        public String email;
        public String password;
    }   

}   
Run Code Online (Sandbox Code Playgroud)

ROUTES

# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~

# Home page
GET     /                           controllers.Application.index()

GET     /login                      controllers.Application.login()

# Map static resources from the /public folder to the /assets URL path
GET     /assets/*file               @controllers.Assets.versioned(path="/public", file: Asset)
Run Code Online (Sandbox Code Playgroud)

mar*_*ira 10

static从控制器的操作中删除关键字.Play 2.5.1默认使用依赖注入,如果要使用static操作,则需要显式配置它.因此,您的登录操作必须如下:

// no static keyword here
public Result login() {
    return ok(login.render(form(Login.class)));
}
Run Code Online (Sandbox Code Playgroud)

更新:

顺便说一句,你在这里混合了很多东西.我建议您在开发2.5.x版本时不要遵循2.1.0指南,因为这两个版本之间存在很多差异.事实上,Play 2.1.0是从2013年2月6日开始的.

以下是一些可以解释代码失败原因的参考资料:

  1. Java路由:依赖注入
  2. 依赖注入控制器
  3. 用依赖注入替换静态控制器