升级IntelliJ后,Play Framework中的控制器的InstantiationException

时间:2014-05-27 19:02:31

标签: java scala intellij-idea playframework guice

我不断收到家庭控制器的InstantiationException,错误如下:

[InstantiationException:project.ui.controllers.HomeController]

case project_ui_controllers_HomeController_index37(params) => {
   call { 
        invokeHandler(play.api.Play.maybeApplication.map(_.global).getOrElse(play.api.DefaultGlobal).getControllerInstance(classOf[project.ui.controllers.HomeController]).index(), HandlerDef(this, "project.ui.controllers.HomeController", "index", Nil,"GET", """""", Routes.prefix + """"""))
   }
}

这是日志输出:

play.api.Application$$anon$1: Execution exception[[InstantiationException:     project.ui.controllers.HomeController]]
at play.api.Application$class.handleError(Application.scala:293) ~[play_2.10.jar:2.2.3]
at play.api.DefaultApplication.handleError(Application.scala:399) [play_2.10.jar:2.2.3]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:264) [play_2.10.jar:2.2.3]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:264) [play_2.10.jar:2.2.3]
at scala.Option.map(Option.scala:145) [scala-library.jar:na]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3.applyOrElse(PlayDefaultUpstreamHandler.scala:264) [play_2.10.jar:2.2.3]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3.applyOrElse(PlayDefaultUpstreamHandler.scala:260) [play_2.10.jar:2.2.3]
at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:344) [scala-library.jar:na]
at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:343) [scala-library.jar:na]
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [scala-library.jar:na]
at play.api.libs.iteratee.Execution$$anon$1.execute(Execution.scala:43) [play-iteratees_2.10.jar:2.2.3]
at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:40) [scala-library.jar:na]
at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:248) [scala-library.jar:na]
at scala.concurrent.Promise$class.complete(Promise.scala:55) [scala-library.jar:na]
at scala.concurrent.impl.Promise$DefaultPromise.complete(Promise.scala:153) [scala-library.jar:na]
at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:235) [scala-library.jar:na]
at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:235) [scala-library.jar:na]
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [scala-library.jar:na]
at scala.concurrent.forkjoin.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1361) [scala-library.jar:na]
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [scala-library.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [scala-library.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [scala-library.jar:na]
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [scala-library.jar:na]
Caused by: java.lang.InstantiationException: project.ui.controllers.HomeController
at java.lang.Class.newInstance(Class.java:359) ~[na:1.7.0_55]
at play.api.GlobalSettings$class.getControllerInstance(GlobalSettings.scala:181) ~[play_2.10.jar:2.2.3]
at play.api.DefaultGlobal$.getControllerInstance(GlobalSettings.scala:189) ~[play_2.10.jar:2.2.3]
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$38$$anonfun$apply$110.apply(routes_routing.scala:496) ~[na:na]
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$38$$anonfun$apply$110.apply(routes_routing.scala:496) ~[na:na]
at play.core.Router$HandlerInvoker$$anon$7$$anon$2.invocation(Router.scala:183) ~[play_2.10.jar:2.2.3]
at play.core.Router$Routes$$anon$1.invocation(Router.scala:377) ~[play_2.10.jar:2.2.3]
at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:56) ~[play_2.10.jar:2.2.3]
at play.core.j.JavaAction$$anon$3.apply(JavaAction.scala:91) ~[play_2.10.jar:2.2.3]
at play.core.j.JavaAction$$anon$3.apply(JavaAction.scala:90) ~[play_2.10.jar:2.2.3]
at play.core.j.FPromiseHelper$$anonfun$flatMap$1.apply(FPromiseHelper.scala:82) ~[play_2.10.jar:2.2.3]
at play.core.j.FPromiseHelper$$anonfun$flatMap$1.apply(FPromiseHelper.scala:82) ~[play_2.10.jar:2.2.3]
at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:251) ~[scala-library.jar:na]
at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:249) ~[scala-library.jar:na]
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [scala-library.jar:na]
at play.core.j.HttpExecutionContext$$anon$2.run(HttpExecutionContext.scala:37) ~[play_2.10.jar:2.2.3]
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:42) ~[akka-actor_2.10.jar:2.2.0]
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386) ~[akka-actor_2.10.jar:2.2.0]
... 4 common frames omitted

我也觉得有趣的是,一旦我将相同的代码移到生产中,我就没有问题。

conf / routes中的路线

GET / @project.ui.controllers.HomeController.index()

Guice Injector Global.java:

public class Global extends GlobalSettings {

private static final Injector INJECTOR = createInjector();

@Override
public void onStart(Application app) {
    super.onStart(app);
    new DatabaseSeeder().seed();
}

@Override
public <A> A getControllerInstance(Class<A> controllerClass) throws Exception {
    return INJECTOR.getInstance(controllerClass);
}

private static Injector createInjector() {
    return Guice.createInjector(new BusinessLayerModule(), new DataLayerModule(), new UtilitiesModule());
}
}

1 个答案:

答案 0 :(得分:1)

这是一个问题,IntelliJ 13.1没有为环境变量找到正确的位置,反过来,无法通过Global.Java初始化Guice(对我来说,Global.Java的位置在application.conf中定义) )。

在使用IntelliJ 13.1之前,我已经能够通过相对路径指定环境变量:

config.file - application.dev.conf

现在,我必须使用绝对路径:

config.file - /home/user/Enviroment/projects/project/conf/application.dev.conf