启动 Play Framework 2.4 应用程序时出现神秘的注入错误消息

Mysterious injection error message when starting Play Framework 2.4 application

我正在尝试将我的应用程序从 Play Framework 2.3 迁移到 2.4。迁移文档指出有一个使用注入的新路由系统,但 2.3 中的旧代码应该仍然有效,这让我们有机会在此过程的后期更改路由器。

不幸的是,情况并非如此。当我启动我的应用程序时,出现此错误。我是否需要添加一些东西来说明我现在想留在旧的路由系统上?报错都和注入有关,没看懂...

CreationException: Unable to create injector, see the following errors:

1) Error in custom provider, Configuration error: Configuration error[Cannot register class [models.S3BrandFile] in Ebean server]
  while locating play.db.ebean.DefaultEbeanConfig$EbeanConfigParser
  at play.db.ebean.EbeanModule.bindings(EbeanModule.java:24):
Binding(interface play.db.ebean.EbeanConfig to ProviderConstructionTarget(class play.db.ebean.DefaultEbeanConfig$EbeanConfigParser) eagerly) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon)
  while locating play.db.ebean.EbeanConfig
    for parameter 0 at play.db.ebean.EbeanDynamicEvolutions.<init>(EbeanDynamicEvolutions.java:36)
  at play.db.ebean.EbeanDynamicEvolutions.class(EbeanDynamicEvolutions.java:33)
  while locating play.db.ebean.EbeanDynamicEvolutions
  at play.db.ebean.EbeanModule.bindings(EbeanModule.java:23):
Binding(class play.api.db.evolutions.DynamicEvolutions to ConstructionTarget(class play.db.ebean.EbeanDynamicEvolutions) eagerly) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon)
  while locating play.api.db.evolutions.DynamicEvolutions
Caused by: Configuration error: Configuration error[Cannot register class [models.S3BrandFile] in Ebean server]
    at play.api.Configuration$.configError(Configuration.scala:178)
    at play.api.Configuration.reportError(Configuration.scala:829)
    at play.Configuration.reportError(Configuration.java:351)
    at play.db.ebean.DefaultEbeanConfig$EbeanConfigParser.parse(DefaultEbeanConfig.java:105)
    at play.db.ebean.DefaultEbeanConfig$EbeanConfigParser.get(DefaultEbeanConfig.java:60)
    at play.db.ebean.DefaultEbeanConfig$EbeanConfigParser.get(DefaultEbeanConfig.java:44)
    at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81)
    at com.google.inject.internal.BoundProviderFactory.provision(BoundProviderFactory.java:72)
    at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:61)
    at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:62)
    at com.google.inject.internal.ProviderToInternalFactoryAdapter.call(ProviderToInternalFactoryAdapter.java:46)
    at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103)
    at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
    at com.google.inject.internal.SingletonScope.get(SingletonScope.java:145)
    at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)
    at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)
    at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)
    at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:104)
    at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
    at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267)
    at com.google.inject.internal.ProviderToInternalFactoryAdapter.call(ProviderToInternalFactoryAdapter.java:46)
    at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103)
    at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
    at com.google.inject.internal.SingletonScope.get(SingletonScope.java:145)
    at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)
    at com.google.inject.internal.FactoryProxy.get(FactoryProxy.java:56)
    at com.google.inject.internal.ProviderToInternalFactoryAdapter.call(ProviderToInternalFactoryAdapter.java:46)
    at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103)
    at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
    at com.google.inject.internal.SingletonScope.get(SingletonScope.java:145)
    at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)
    at com.google.inject.internal.InternalInjectorCreator.call(InternalInjectorCreator.java:205)
    at com.google.inject.internal.InternalInjectorCreator.call(InternalInjectorCreator.java:199)
    at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
    at com.google.inject.internal.InternalInjectorCreator.loadEagerSingletons(InternalInjectorCreator.java:199)
    at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:180)
    at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110)
    at com.google.inject.Guice.createInjector(Guice.java:96)
    at com.google.inject.Guice.createInjector(Guice.java:73)
    at com.google.inject.Guice.createInjector(Guice.java:62)
    at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:126)
    at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:93)
    at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
    at play.core.server.DevServerStart$$anonfun$mainDev$$anon$$anonfun$get$$anonfun$apply$$anonfun$$anonfun.apply(DevServerStart.scala:153)
    at play.core.server.DevServerStart$$anonfun$mainDev$$anon$$anonfun$get$$anonfun$apply$$anonfun$$anonfun.apply(DevServerStart.scala:150)
    at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
    at play.core.server.DevServerStart$$anonfun$mainDev$$anon$$anonfun$get$$anonfun$apply$$anonfun.apply(DevServerStart.scala:150)
    at play.core.server.DevServerStart$$anonfun$mainDev$$anon$$anonfun$get$$anonfun$apply$$anonfun.apply(DevServerStart.scala:121)
    at scala.Option.map(Option.scala:145)
    at play.core.server.DevServerStart$$anonfun$mainDev$$anon$$anonfun$get$$anonfun$apply.apply(DevServerStart.scala:121)
    at play.core.server.DevServerStart$$anonfun$mainDev$$anon$$anonfun$get$$anonfun$apply.apply(DevServerStart.scala:119)
    at scala.util.Success.flatMap(Try.scala:200)
    at play.core.server.DevServerStart$$anonfun$mainDev$$anon$$anonfun$get.apply(DevServerStart.scala:119)
    at play.core.server.DevServerStart$$anonfun$mainDev$$anon$$anonfun$get.apply(DevServerStart.scala:111)
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1(Future.scala:24)
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
    at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: java.lang.ExceptionInInitializerError
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at play.db.ebean.DefaultEbeanConfig$EbeanConfigParser.parse(DefaultEbeanConfig.java:103)
    ... 57 more
Caused by: java.lang.RuntimeException: There is no started application
    at scala.sys.package$.error(package.scala:27)
    at play.api.Play$$anonfun$current.apply(Play.scala:71)
    at play.api.Play$$anonfun$current.apply(Play.scala:71)
    at scala.Option.getOrElse(Option.scala:120)
    at play.api.Play$.current(Play.scala:71)
    at play.api.Play.current(Play.scala)
    at play.Play.application(Play.java:17)
    at models.S3BrandFile.<clinit>(S3BrandFile.java:25)
    ... 60 more

我不确定这是否是正确的答案,但它对我有用。在花时间将旧静态路由器转换为新格式后,我一开始就遇到了完全相同的错误。所以很明显这个错误不是这个引起的

所以我在 class 中搜索可能 "strange" 的东西。我发现我的 class 中有一个 final 静态变量。一旦我把这个变量放在评论中,错误就变成了另一个 class 具有完全相同的静态变量。在 3 或 4 class 之后,它进入了另一个错误,但至少这个错误消失了。

这在 2.1、2.2 和 2.3 版本中没有问题。我不明白为什么它现在失败了,迁移文档中也没有提到这个。

忠告:迁移 Play Framework 应用程序真的很痛苦。准备好沮丧并为此计划大量的时间和资源。