ProvisionException: Unable to provision. Play Framework

谁说胖子不能爱 提交于 2020-01-07 04:14:22

问题


when I put this line into my application I'm no longer able to start my application and I don't know why.
I'm using 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<>();

If I generate the form in the controller I get the error.

Error I get:

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

What causes this? Any ideas?

Edit:

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

来源:https://stackoverflow.com/questions/44324523/provisionexception-unable-to-provision-play-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!