代码之家  ›  专栏  ›  技术社区  ›  vortexkd

Play Framework 2.6.x ebean:数据源仅在生产环境中为空

  •  0
  • vortexkd  · 技术社区  · 6 年前

    :9.0.4(我也试过10.0.2)

    播放版本 :2.6.15(也是2.6.18)

    扮演埃宾 : 4.1.3

    敬请见识!

    这是完整的日志,下面是我的conf设置。

    [warn] o.h.v.m.ParameterMessageInterpolator - HV000184: ParameterMessageInterpolator has been chosen, EL interpolation will not be supported
    [error] io.ebean.Ebean - Error trying to create the default EbeanServer
    java.lang.RuntimeException: DataSource user is null?
            at org.avaje.datasource.pool.ConnectionPool.<init>(ConnectionPool.java:207)
            at org.avaje.datasource.core.Factory.createPool(Factory.java:15)
            at io.ebeaninternal.server.core.DefaultContainer.getDataSourceFromConfig(DefaultContainer.java:334)
            at io.ebeaninternal.server.core.DefaultContainer.setDataSource(DefaultContainer.java:278)
            at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:117)
            at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:88)
            at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:45)
            at io.ebean.EbeanServerFactory.create(EbeanServerFactory.java:58)
            at io.ebean.Ebean$ServerManager.getWithCreate(Ebean.java:202)
            at io.ebean.Ebean$ServerManager.<init>(Ebean.java:160)
    Oops, cannot start the server.
    Exception in thread "main" com.google.common.util.concurrent.UncheckedExecutionException: java.lang.IllegalArgumentException
            at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2218)
            at com.google.common.cache.LocalCache.get(LocalCache.java:4147)
            at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4151)
            at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:5140)
            at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:5146)
            at com.google.inject.internal.util.StackTraceElements.forMember(StackTraceElements.java:70)
            at com.google.inject.internal.Errors.formatSource(Errors.java:817)
            at com.google.inject.internal.Errors.formatSource(Errors.java:796)
            at com.google.inject.internal.Errors.formatInjectionPoint(Errors.java:849)
            at com.google.inject.internal.Errors.formatSource(Errors.java:811)
            at com.google.inject.internal.Errors.formatSource(Errors.java:796)
            at com.google.inject.internal.Errors.format(Errors.java:590)
            at com.google.inject.CreationException.getMessage(CreationException.java:50)
            at java.base/java.lang.Throwable.getLocalizedMessage(Throwable.java:396)
            at java.base/java.lang.Throwable.toString(Throwable.java:485)
            at java.base/java.lang.String.valueOf(String.java:2788)
            at java.base/java.io.PrintStream.println(PrintStream.java:897)
            at java.base/java.lang.Throwable$WrappedPrintStream.println(Throwable.java:752)
            at java.base/java.lang.Throwable.printStackTrace(Throwable.java:659)
            at java.base/java.lang.Throwable.printStackTrace(Throwable.java:648)
            at java.base/java.lang.Throwable.printStackTrace(Throwable.java:639)
            at play.core.server.RealServerProcess.$anonfun$exit$1(ServerProcess.scala:49)
            at play.core.server.RealServerProcess.$anonfun$exit$1$adapted(ServerProcess.scala:49)
            at scala.Option.foreach(Option.scala:257)
            at play.core.server.RealServerProcess.exit(ServerProcess.scala:49)
            at play.core.server.ProdServerStart$.start(ProdServerStart.scala:74)
            at play.core.server.ProdServerStart$.main(ProdServerStart.scala:25)
            at play.core.server.ProdServerStart.main(ProdServerStart.scala)
    Caused by: java.lang.IllegalArgumentException
            at com.google.inject.internal.asm.$ClassReader.<init>(Unknown Source)
            at com.google.inject.internal.asm.$ClassReader.<init>(Unknown Source)
            at com.google.inject.internal.asm.$ClassReader.<init>(Unknown Source)
            at com.google.inject.internal.util.LineNumbers.<init>(LineNumbers.java:66)
            at com.google.inject.internal.util.StackTraceElements$1.load(StackTraceElements.java:46)
            at com.google.inject.internal.util.StackTraceElements$1.load(StackTraceElements.java:43)
            at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3708)
            at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2416)
            at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2299)
            at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2212)
            ... 27 more
    

    应用程序配置设置:

    db {
      default.driver=com.mysql.jdbc.Driver
      default.url="jdbc:mysql://1.1.1.1/db_name?characterEncoding=UTF8&autoReconnect=true&useSSL=false"
      default.username=user
      default.password="pwd"
    }
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   vortexkd    6 年前

    所以这似乎对我有用。这个问题本质上是不稳定的,所以我不能确定。

    @Inject
        public Repository(EbeanConfig ebeanConfig, DynamicEvolutions dynamicEvolutions,
                          DatabaseExecutionContext executionContext, Config config) {
            this.ebeanServer = Ebean.getServer(ebeanConfig.defaultServer());
            this.executionContext = executionContext;
        }
    

    所以这基本上是将EbeanConfig和DynamicEvolutions注入到任何调用 Ebean.getServer();

    我在这个问题上发现了这个,

    https://github.com/playframework/play-ebean/issues/51

    在2.6.x和ebean 4.1.3中使用了这个,如前所述,它似乎起到了作用。