Play Framework 2.6.x ebean:仅在生产中DataSource为null

时间:2018-09-05 08:22:03

标签: ebean playframework-2.6

Java版本:9.0.4(我也尝试使用10.0.2)

播放版本:2.6.15(也是2.6.18)

Play-ebean :4.1.3

使用sbt运行项目可以正常运行,但是尝试在生产环境(完全相同的环境)中运行它会导致此错误。 “ DataSource用户为空?”

任何见识都受到赞赏!

这是完整的日志,我的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 个答案:

答案 0 :(得分:0)

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

@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上使用了它,并且如上所述,它似乎已经起作用。