Setter 和 getter 方法在为 Play 2 编码时应该存在于模型 bean 中。4.x + EBean 6.8.1

Setter and getter methods should exist in model bean when coding for Play 2.4.x + EBean 6.8.1

我正在将 Play 升级到 2.4.2,将 EBean 升级到 6.8.1,因为我认为 EBean 6.8.1 对 postgresql 数据库的 jsonb 数据类型提供了更多支持。

IDE :

idea 15

plugins.sbt:

addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "2.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")

build.sbt:

scalaVersion := "2.11.6"
libraryDependencies ++= Seq(
  javaJdbc, cache, javaWs,
  filters,
  "org.postgresql" % "postgresql" % "9.4-1201-jdbc41",
  "org.avaje.ebeanorm" % "avaje-ebeanorm" % "6.8.1",
  "org.avaje.ebeanorm" % "avaje-ebeanorm-agent" % "4.7.1"
  )

编译成功。 但是当我 运行 项目时,出现以下错误:

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

1) Error in custom provider, Configuration error: Configuration error[Cannot register class [models.TravelLine] 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.TravelLine] 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:146)
    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:230)
    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:1423)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:902)
    at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1689)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1644)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    models/TravelLine.<init>()V @55: invokevirtual
  Reason:
    Type uninitialized 47 (current frame, stack[2]) is not assignable to 'java/util/List'
  Current Frame:
    bci: @55
    flags: { }
    locals: { 'models/TravelLine', uninitialized 47, uninitialized 47 }
    stack: { 'models/TravelLine', uninitialized 47, uninitialized 47 }
  Bytecode:
    0x0000000: 2ab7 0052 2abb 0054 592a b700 57b5 0059
    0x0000010: 2abb 005b 59b7 005c 4d4c 2b2c b600 602a
    0x0000020: bb00 5b59 b700 5c4d 4c2b 2cb6 0063 2abb
    0x0000030: 0065 594d 4c2b 2cb6 0069 b1            

    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:344)
    at play.db.ebean.DefaultEbeanConfig$EbeanConfigParser.parse(DefaultEbeanConfig.java:103)
    ... 58 more

有人给我一些建议吗?非常感谢。

我有一个非常相似的设置,我能看到的唯一区别是我的 build.sbt关于ebean我只有这个:

"org.avaje" % "avaje-agentloader" % "2.1.2" withSources(),

而在我的 plugins.sbt 我只有这个:

addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "2.0.0")

已解决: 我为 java.util.List 类型的 属性 添加了 setter 和 getter 方法,然后错误消失了。

错误代码:

"traffics" 属性 TravelLine 中没有 setter 和 getter 方法 class

    @ManyToMany
    public List<Traffic> traffics = new ArrayList<Traffic>();

固定代码:

添加了

setter和getter方法

    @ManyToMany
    public List<Traffic> traffics = new ArrayList<Traffic>();

    public List<Traffic> getTraffics() {
        return traffics;
    }

    public void setTraffics(List<Traffic> traffics) {
         this.traffics = traffics;
    }