Play框架-值登录不是控制器的成员. [英] Play Framework - value login is not a member of controllers.Application

查看:87
本文介绍了Play框架-值登录不是控制器的成员.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm running the latest Play Framework 2.5.1 and I'm getting an error from my log on page:

错误:

value login is not a member of controllers.Application

我尝试添加@符号,即:

@controllers.Application.login()

并从build.sbt中移除进样器,清理/清理文件并在"CMD"中进行更新.我正在使用 https://www.playframework.com/documentation/2.1中的示例. 0/JavaGuide .

And removing the injector from the build.sbt, clean up/ clean-files and updates in "CMD". I'm using the sample from 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>

控制器

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;
    }   

}   

路线

# 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)

推荐答案

从控制器的操作中删除static关键字. Play 2.5.1默认情况下使用依赖项注入,如果您想使用static动作,则需要

Remove the static keyword from your controller's actions. Play 2.5.1 uses dependency injection by default and if you want to use static actions, you need to explicitly configure it. So, your login action must be like:

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

更新:

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

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

Here are some references that explain why your code was failing:

  1. Java路由:依赖注入
  2. 依赖注入控制器
  3. 已替换具有依赖项注入的静态控制器
  1. Java Routing: Dependency Injection
  2. Dependency injecting controllers
  3. Replaced static controllers with dependency injection

这篇关于Play框架-值登录不是控制器的成员.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆