java – Play Framework 2.4不接受控制器的“公共静态结果”

我尝试使用Play Framework 2.4和Mac中的JDK8启动应用程序,当我使用./activator下载基础时新建项目播放- java模板代码包含下一个:

项目/应用/ controlles / Application.java

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 index() {...

将“static”添加到index()

我收到这个错误

Compilation error
value index is not a member of controllers.Application
.../conf/routes:6
4 # ~~~~
5 # Home page
6 GET     /                           controllers.Application.index()

我不知道为什么因为在所有的例子中都使用了static for Result

解决方法

您可能仍在使用旧式路由.

documentation

Injected routes generator
By default,Play will generate a static router,that assumes that all actions are static methods. By configuring Play to use the injected routes generator,you can get Play to generate a router that will declare all the controllers that it routes to as dependencies,allowing your controllers to be dependency injected themselves.

We recommend always using the injected routes generator,the static routes generator exists primarily as a tool to aid migration so that existing projects don’t have to make all their controllers non static at once.

To enable the injected routes generator,add the following to your build settings in build.sbt:

routesGenerator := InjectedRoutesGenerator

或者,你可以坚持使用静态路由器(但如果你正在创建一个新的应用程序,为什么会这样?)并在动作参考前加上@

GET        /some/path        @controllers.Application.index()

相关文章

ArrayList简介:ArrayList 的底层是数组队列,相当于动态数组。与 Java 中的数组相比,它的容量能动态增...
一、进程与线程 进程:是代码在数据集合上的一次运行活动,是系统进行资源分配和调度的基本单位。 线程...
本文为博客园作者所写: 一寸HUI,个人博客地址:https://www.cnblogs.com/zsql/ 简单的一个类...
#############java面向对象详解#############1、面向对象基本概念2、类与对象3、类和对象的定义格式4、...
一、什么是异常? 异常就是有异于常态,和正常情况不一样,有错误出错。在java中,阻止当前方法或作用域...
Collection接口 Collection接口 Collection接口 Collection是最基本的集合接口,一个Collection代表一组...