Play框架:DB演变之后或期间出现意外异常

时间:2014-12-09 23:20:42

标签: java playframework

突然之后,我确认了我的Play-Framework项目的数据库演变后,我发现了这个奇怪的错误:

Unexpected exception
NullPointerException: null
No source available, here is the exception stack trace:
->java.lang.NullPointerException: 
     com.avaje.ebean.Ebean.save(Ebean.java:533)
     Global.onStart(Global.java:18)
     play.core.j.JavaGlobalSettingsAdapter.onStart(JavaGlobalSettingsAdapter.scala:22)
     play.api.GlobalPlugin.onStart(GlobalSettings.scala:220)
     play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:91)
     play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:91)
     scala.collection.immutable.List.foreach(List.scala:383)
     play.api.Play$$anonfun$start$1.apply$mcV$sp(Play.scala:91)
     play.api.Play$$anonfun$start$1.apply(Play.scala:91)
     play.api.Play$$anonfun$start$1.apply(Play.scala:91)
     play.utils.Threads$.withContextClassLoader(Threads.scala:21)
     play.api.Play$.start(Play.scala:90)
     play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:157)
     play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:130)
     scala.Option.map(Option.scala:145)
     play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:130)
     play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:128)
     scala.util.Success.flatMap(Try.scala:230)
     play.core.ReloadableApplication$$anonfun$get$1.apply(ApplicationProvider.scala:128)
     play.core.ReloadableApplication$$anonfun$get$1.apply(ApplicationProvider.scala:120)
     scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
     scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
     scala.concurrent.forkjoin.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1361)
     scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
     scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
     scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
     scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

我不知道如何调试此错误,没有任何内容指向我的任何文件。 这是输入我输入的输出:

! @6kekc98dk - Internal server error, for (GET) [/] ->

play.api.db.evolutions.InvalidDatabaseRevision: Database 'default' needs evolution![An SQL script need to be run on your database.]
    at play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$1$$anonfun$apply$1.apply$mcV$sp(Evolutions.scala:510) ~[play-jdbc_2.11-2.3.6.jar:2.3.6]
    at play.api.db.evolutions.EvolutionsPlugin.withLock(Evolutions.scala:531) ~[play-jdbc_2.11-2.3.6.jar:2.3.6]
    at play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$1.apply(Evolutions.scala:485) ~[play-jdbc_2.11-2.3.6.jar:2.3.6]
    at play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$1.apply(Evolutions.scala:483) ~[play-jdbc_2.11-2.3.6.jar:2.3.6]
    at scala.collection.immutable.List.foreach(List.scala:383) ~[scala-library-2.11.1.jar:na]
[warn] play - Error stopping plugin
java.lang.NullPointerException: null
    at play.libs.ws.ning.NingWSPlugin.onStop(NingWSPlugin.java:31) ~[play-java-ws_2.11-2.3.6.jar:2.3.6]
    at play.api.Play$$anonfun$stop$1$$anonfun$apply$1$$anonfun$apply$mcV$sp$2.apply(Play.scala:108) [play_2.11-2.3.6.jar:2.3.6]
    at play.api.Play$$anonfun$stop$1$$anonfun$apply$1$$anonfun$apply$mcV$sp$2.apply(Play.scala:107) [play_2.11-2.3.6.jar:2.3.6]
    at scala.collection.immutable.List.foreach(List.scala:383) [scala-library-2.11.1.jar:na]
    at play.api.Play$$anonfun$stop$1$$anonfun$apply$1.apply$mcV$sp(Play.scala:107) [play_2.11-2.3.6.jar:2.3.6]
[info] play - database [default] connected at jdbc:h2:mem:play
[error] application - 

! @6kekd052e - Internal server error, for (GET) [/] ->

play.api.UnexpectedException: Unexpected exception[NullPointerException: null]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:166) ~[play_2.11-2.3.6.jar:2.3.6]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:130) ~[play_2.11-2.3.6.jar:2.3.6]
    at scala.Option.map(Option.scala:145) ~[scala-library-2.11.1.jar:na]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:130) ~[play_2.11-2.3.6.jar:2.3.6]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:128) ~[play_2.11-2.3.6.jar:2.3.6]
Caused by: java.lang.NullPointerException: null
    at com.avaje.ebean.Ebean.save(Ebean.java:533) ~[avaje-ebeanorm-3.3.4.jar:na]
    at Global.onStart(Global.java:18) ~[na:na]
    at play.core.j.JavaGlobalSettingsAdapter.onStart(JavaGlobalSettingsAdapter.scala:22) ~[play_2.11-2.3.6.jar:2.3.6]
    at play.api.GlobalPlugin.onStart(GlobalSettings.scala:220) ~[play_2.11-2.3.6.jar:2.3.6]
    at play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:91) ~[play_2.11-2.3.6.jar:2.3.6]

Global.java:

import com.avaje.ebean.Ebean;
import models.MediumModel;
import models.MobileAppModule;
import models.LandingModule;
import play.Application;
import play.GlobalSettings;
import play.libs.Yaml;

import java.util.List;

/**
 * Created by usr on 11/11/14.
 */
public class Global extends GlobalSettings{
    @Override
    public void onStart(Application app) {
        if (MediumModel.find.findRowCount() == 0) {
            Ebean.save((List) Yaml.load("initial-medium-data.yml"));
        }
        if (MobileAppModule.find.findRowCount() == 0) {
            Ebean.save((List) Yaml.load("initial-app-data.yml"));
        }
        if (LandingModule.find.findRowCount() == 0) {
            Ebean.save((List) Yaml.load("initial-frontend-data.yml"));
        }

    }
}

1 个答案:

答案 0 :(得分:2)

Global.java中的这一行返回null,因此在Ebean类中抛出异常:

Yaml.load("initial-medium-data.yml")

确保{class 1}在您的类路径上,文件路径正确且文件本身不为空。