ProvisionException:无法配置。玩框架

时间:2017-06-02 08:44:00

标签: java playframework

当我将这一行放入我的应用程序时,我不再能够启动我的应用程序而且我不知道为什么 我正在使用Play 2.5。

public class HomeController extends Controller {


    Form<User> userForm = Form.form(User.class); // get error if I put this line in

    public Hashtable<Integer, String> hmap = new Hashtable<>();

如果我在控制器中生成表单,我会收到错误。

我得到错误:

ProvisionException: Unable to provision, see the following errors: 

1) Error injecting constructor, java.lang.RuntimeException: There is no started application
 at controllers.HomeController.<init>(HomeController.java:15) 
 while locating controllers.HomeController 
  for parameter 1 at router.Routes.<init>(Routes.scala:32) 
 while locating router.Routes 
 while locating play.api.inject.RoutesProvider 
 while locating play.api.routing.Router 
  for parameter 0 at play.api.http.JavaCompatibleHttpRequestHandler.<init>(HttpRequestHandler.scala:201) 
 while locating play.api.http.JavaCompatibleHttpRequestHandler 
 while locating play.api.http.HttpRequestHandler 
  for parameter 4 at play.api.DefaultApplication.<init>(Application.scala:221) 
 at play.api.DefaultApplication.class(Application.scala:221) 
 while locating play.api.DefaultApplication 
 while locating play.api.Application 

1 error

是什么原因引起的?有什么想法吗?

修改

HomeController.java

package controllers;

import play.mvc.*;
import java.util.*;
import models.User;
import play.data.Form;


public class HomeController extends Controller {

Form<User> filledForm = Form.form(User.class);
public Hashtable<Integer, String> hmap = new Hashtable<>();

public Result index() {

    return ok(views.html.index.render());
}

public Result saveData() {


    User user = filledForm.bindFromRequest().get();

    if (filledForm.hasErrors()) {
        // process
    } else {
        // contactForm.get().firstName should be filled with the correct data
        System.out.println("Nothing to show here.");
    }


    System.out.println(user.name);
    System.out.println(user.tableNr);

    return ok(views.html.index.render());
}

0 个答案:

没有答案