cannot start in PROD mode when assigning port explicitly with ebean
Play Version (2.5.x / etc)
2.5.x
API (Scala / Java / Neither / Both)
Java
Operating System (Ubuntu 15.10 / MacOS 10.10 / Windows 10)
CentOS 7
JDK (Oracle 1.8.0_72, OpenJDK 1.8.x, Azul Zing)
openJDK 1.8.x
Library Dependencies
ebean
Expected Behavior
when I run:
applicationName/target/universal/stage/bin/applicationName -Dconfig.resource=production.conf -Dplay.evolutions.db.default.autoApply=true
The application works well.
However, when I run:
applicationName/target/universal/stage/bin/applicationName -Dhttp.port=9000 -Dconfig.resource=production.conf -Dplay.evolutions.db.default.autoApply=true
application cannot start.
Please describe the expected behavior of the issue, starting from the first action.
Actual Behavior
[error] c.a.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:204)
at org.avaje.datasource.Factory.createPool(Factory.java:12)
at com.avaje.ebeaninternal.server.core.DefaultContainer.getDataSourceFromConfig(DefaultContainer.java:309)
at com.avaje.ebeaninternal.server.core.DefaultContainer.setDataSource(DefaultContainer.java:262)
at com.avaje.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:105)
at com.avaje.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:77)
at com.avaje.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:44)
at com.avaje.ebean.EbeanServerFactory.create(EbeanServerFactory.java:55)
at com.avaje.ebean.Ebean$ServerManager.getWithCreate(Ebean.java:201)
at com.avaje.ebean.Ebean$ServerManager.<init>(Ebean.java:159)
Oops, cannot start the server.
com.google.inject.CreationException: Unable to create injector, see the following errors:
1) Error injecting constructor, java.lang.NoClassDefFoundError: Could not initialize class com.avaje.ebean.Ebean
at play.db.ebean.EbeanDynamicEvolutions.<init>(EbeanDynamicEvolutions.java:55)
at play.db.ebean.EbeanDynamicEvolutions.class(EbeanDynamicEvolutions.java:44)
while locating play.db.ebean.EbeanDynamicEvolutions
at play.db.ebean.EbeanModule.bindings(EbeanModule.java:24):
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$1)
while locating play.api.db.evolutions.DynamicEvolutions
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.avaje.ebean.Ebean
at com.avaje.ebean.EbeanServerFactory.create(EbeanServerFactory.java:73)
at play.db.ebean.EbeanDynamicEvolutions.lambda$start$2(EbeanDynamicEvolutions.java:118)
at java.util.HashMap.forEach(HashMap.java:1288)
at play.db.ebean.EbeanDynamicEvolutions.start(EbeanDynamicEvolutions.java:114)
at play.db.ebean.EbeanDynamicEvolutions.<init>(EbeanDynamicEvolutions.java:58)
at play.db.ebean.EbeanDynamicEvolutions$$FastClassByGuice$$52c94231.newInstance(<generated>)
at com.google.inject.internal.cglib.reflect.$FastConstructor.newInstance(FastConstructor.java:40)
at com.google.inject.internal.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:61)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:105)
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$1.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$1.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$1.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$1.get(SingletonScope.java:145)
at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)
at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:205)
at com.google.inject.internal.InternalInjectorCreator$1.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:84)
at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:181)
at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:123)
at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
at play.core.server.ProdServerStart$.start(ProdServerStart.scala:47)
at play.core.server.ProdServerStart$.main(ProdServerStart.scala:22)
at play.core.server.ProdServerStart.main(ProdServerStart.scala)
```[tasklist]
### Tasks
Hello @wei-hai, could you please provide a small project that shows this problem? I was not able to reproduce this.
Also, the mailing list would be a better place to discuss this. Github issues are for reporting bugs and feature requests in Play, not for general discussion and getting help. So, if this is more a doubt than a reproducible bug, I encourage you to move the discussion to the mailing list.
I'm having this exact same problem using 2.6. Did you guys ever find out what was going on?
For me too, after removing one of the parameters from initialization command the error was gone. To reproduce this you can use this project https://github.com/joaocraveiro/versus. I've deployed it on heroku as it is and it throws the error. If you remove "-Ddb.default.url=${DATABASE_URL}" from the Procfile it's gone.
I have the same problem than seems I switched to Play 2.6.0-RC2 and Ebean 4.0.0-M3. The error seems more "random" to me, because it happens randomly in development and in prod...
2017-06-08 15:57:09,368 [INFO] from application in main - Creating Pool for datasource 'default' 2017-06-08 15:57:09,422 [WARN] from com.zaxxer.hikari.HikariConfig in main - The initializationFailFast propery is deprecated, see initializationFailTimeout 2017-06-08 15:57:09,860 [INFO] from play.api.db.DefaultDBApi in main - Database [default] connected at jdbc:mysql:///?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC 2017-06-08 15:57:13,558 [ERROR] from io.ebean.Ebean in application-akka.actor.default-dispatcher-6 - Error trying to create the default EbeanServer java.lang.RuntimeException: DataSource user is null? at org.avaje.datasource.pool.ConnectionPool.
(ConnectionPool.java:204) at org.avaje.datasource.Factory.createPool(Factory.java:12) at io.ebeaninternal.server.core.DefaultContainer.getDataSourceFromConfig(DefaultContainer.java:310) at io.ebeaninternal.server.core.DefaultContainer.setDataSource(DefaultContainer.java:265) at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:108) at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:79) at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:44) at io.ebean.EbeanServerFactory.create(EbeanServerFactory.java:55) at io.ebean.Ebean$ServerManager.getWithCreate(Ebean.java:201) at io.ebean.Ebean$ServerManager. (Ebean.java:159) at io.ebean.Ebean$ServerManager. (Ebean.java:124) at io.ebean.Ebean. (Ebean.java:118) at io.ebean.Finder.db(Finder.java:101) at io.ebean.Finder.query(Finder.java:157) at modules.testregistration.RemoveTestRegistrationActor.onReceive(RemoveTestRegistrationActor.java:22) at akka.actor.UntypedAbstractActor$$anonfun$receive$1.applyOrElse(AbstractActor.scala:243) at akka.actor.Actor.aroundReceive(Actor.scala:513) at akka.actor.Actor.aroundReceive$(Actor.scala:511) at akka.actor.AbstractActor.aroundReceive(AbstractActor.scala:132) at akka.actor.ActorCell.receiveMessage(ActorCell.scala:527) at akka.actor.ActorCell.invoke(ActorCell.scala:496) at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:257) at akka.dispatch.Mailbox.run(Mailbox.scala:224) at akka.dispatch.Mailbox.exec(Mailbox.scala:234) at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) Uncaught error from thread [application-akka.actor.default-dispatcher-6] shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled for ActorSystem[application] java.lang.ExceptionInInitializerError at io.ebean.Finder.db(Finder.java:101) at io.ebean.Finder.query(Finder.java:157) at modules.testregistration.RemoveTestRegistrationActor.onReceive(RemoveTestRegistrationActor.java:22) at akka.actor.UntypedAbstractActor$$anonfun$receive$1.applyOrElse(AbstractActor.scala:243) at akka.actor.Actor.aroundReceive(Actor.scala:513) at akka.actor.Actor.aroundReceive$(Actor.scala:511) at akka.actor.AbstractActor.aroundReceive(AbstractActor.scala:132) at akka.actor.ActorCell.receiveMessage(ActorCell.scala:527) at akka.actor.ActorCell.invoke(ActorCell.scala:496) at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:257) at akka.dispatch.Mailbox.run(Mailbox.scala:224) at akka.dispatch.Mailbox.exec(Mailbox.scala:234) at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) Caused by: java.lang.RuntimeException: java.lang.RuntimeException: DataSource user is null? at io.ebean.Ebean$ServerManager. (Ebean.java:164) at io.ebean.Ebean$ServerManager. (Ebean.java:124) at io.ebean.Ebean. (Ebean.java:118) ... 16 more Caused by: java.lang.RuntimeException: DataSource user is null? at org.avaje.datasource.pool.ConnectionPool. (ConnectionPool.java:204) at org.avaje.datasource.Factory.createPool(Factory.java:12) at io.ebeaninternal.server.core.DefaultContainer.getDataSourceFromConfig(DefaultContainer.java:310) at io.ebeaninternal.server.core.DefaultContainer.setDataSource(DefaultContainer.java:265) at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:108) at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:79) at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:44) at io.ebean.EbeanServerFactory.create(EbeanServerFactory.java:55) at io.ebean.Ebean$ServerManager.getWithCreate(Ebean.java:201) at io.ebean.Ebean$ServerManager. (Ebean.java:159) ... 18 more 2017-06-08 15:57:13,588 [ERROR] from akka.actor.ActorSystemImpl in application-akka.actor.default-dispatcher-5 - Uncaught error from thread [application-akka.actor.default-dispatcher-6] shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled 2017-06-08 15:57:13,599 [INFO] from akka.actor.CoordinatedShutdown in application-akka.actor.default-dispatcher-5 - Starting coordinated shutdown from JVM shutdown hook
Hi,
I was not able to reproduce it using Play 2.6.0 RC2 and play-ebean 4.0.0-RC1. Here are the changes that I've made to https://github.com/joaocraveiro/versus:
diff --git a/project/plugins.sbt b/project/plugins.sbt
index 624e4c5..f281054 100644
--- a/project/plugins.sbt
+++ b/project/plugins.sbt
@@ -1,4 +1,4 @@
// The Play plugin
-addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.0-M5")
+addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.0-RC2")
addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")
-addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "4.0.0-M3")
+addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "4.0.0-RC1")
After that:
export PORT=9000
export DATABASE_URL="jdbc:postgresql://localhost/issue_7017"
export JDBC_DATABASE_USERNAME=postgres
export JDBC_DATABASE_PASSWORD=dummy
export JDBC_DATABASE_URL="jdbc:postgresql://localhost/issue_7017"
sbt clean stage
foreman start
And I get the application running:
17:58:48 web.1 | started with pid 37604
17:58:50 web.1 | [info] application - Creating Pool for datasource 'default'
17:58:50 web.1 | [warn] c.z.h.HikariConfig - The initializationFailFast propery is deprecated, see initializationFailTimeout
17:58:50 web.1 | [info] p.a.d.DefaultDBApi - Database [default] connected at jdbc:h2:mem:play_env
17:58:51 web.1 | [info] application - Starting module...
17:58:51 web.1 | [info] application - Profiles: 1
17:58:51 web.1 | [warn] o.h.v.m.ParameterMessageInterpolator - HV000184: ParameterMessageInterpolator has been chosen, EL interpolation will not be supported
17:58:51 web.1 | [info] play.api.Play - Application started (Prod)
17:58:51 web.1 | [info] p.c.s.AkkaHttpServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
@joaocraveiro do you have environment variables for JDBC_DATABASE_USERNAME and JDBC_DATABASE_PASSWORD when running locally? Can you confirm that all the evolutions could be successfully applicated to your database?
You can better figure out what is happening in your application by adding the following conf/loback.xml file:
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<!-- We use short exception stack trace logging to limit output for travis. -->
<!-- Change to full if you need to do further debugging, but never commit that. -->
<pattern>%level %logger{15} - %message%n%ex{short}</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
</configuration>
@wei-hai and @Flo354 could you also please try with the new versions of Play and play-ebean and with a more verbose log?
@marcospereira evolutions were ok and yes I do have those variables but never had the problem running locally (maybe because I don't use any variables in the command to start the server locally, I read them all from the conf file, while on Heroku I need to so it can bind the database configs automatically). I'd guess it was a problem with either the length of the start command or a conflict between variables in both the start command and in the conf file.
@marcospereira please explain this line:
[warn] o.h.v.m.ParameterMessageInterpolator - HV000184: ParameterMessageInterpolator has been chosen, EL interpolation will not be supported
I see it in my console, and I don't know what does it mean
I found and fixed the problem for my crash. There were conflicts with versions...
Solved by doing this in my build.sbt
libraryDependencies ++= Seq(
...
"com.typesafe.play" % "play-jdbc_2.12" % "2.6.0-RC2",
"com.typesafe.play" % "play-jdbc-api_2.12" % "2.6.0-RC2",
"com.typesafe.play" % "play-jdbc-evolutions_2.12" % "2.6.0-RC2",
"com.typesafe.play" % "play-java-jdbc_2.12" % "2.6.0-RC2"
)
dependencyOverrides ++= Set(
"com.typesafe.play" % "play-jdbc_2.12" % "2.6.0-RC2",
"com.typesafe.play" % "play-jdbc-api_2.12" % "2.6.0-RC2",
"com.typesafe.play" % "play-jdbc-evolutions_2.12" % "2.6.0-RC2",
"com.typesafe.play" % "play-java-jdbc_2.12" % "2.6.0-RC2"
)
@PromanSEW This warning is from Hibernate Validator. We removed the javax.el-api dependency in playframework/playframework#6805 because we did not make use EL interpolation anyway. It will not affect you. Actually we could disable the warning to not confuse people...
@Flo354 this was happening because play-ebean was bringing the wrong (old) Play dependencies. This should be working now since it is depending on the right Play version.
I'm closing this issue.
The error surfaced again (play 2.6.2)...
I did not have the problem when starting the project in dev mode but when I pushed the app to my production servers, it did not work. Still the same "Error trying to create the default EbeanServer" with : java.lang.RuntimeException: DataSource user is null?
Here is the stack trace from CloudWatch :
2017-07-26 10:21:31,100 [ERROR] from io.ebean.Ebean in application-akka.actor.default-dispatcher-3 - Error trying to create the default EbeanServer java.lang.RuntimeException: DataSource user is null? at org.avaje.datasource.pool.ConnectionPool.
(ConnectionPool.java:204) at org.avaje.datasource.Factory.createPool(Factory.java:12) at io.ebeaninternal.server.core.DefaultContainer.getDataSourceFromConfig(DefaultContainer.java:310) at io.ebeaninternal.server.core.DefaultContainer.setDataSource(DefaultContainer.java:265) at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:108) at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:79) at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:44) at io.ebean.EbeanServerFactory.create(EbeanServerFactory.java:55) at io.ebean.Ebean$ServerManager.getWithCreate(Ebean.java:201) at io.ebean.Ebean$ServerManager. (Ebean.java:159) at io.ebean.Ebean$ServerManager. (Ebean.java:124) at io.ebean.Ebean. (Ebean.java:118) at io.ebean.Finder.db(Finder.java:101) at io.ebean.Finder.query(Finder.java:157) at modules.testregistration.RemoveTestRegistrationActor.onReceive(RemoveTestRegistrationActor.java:23) at akka.actor.UntypedAbstractActor$$anonfun$receive$1.applyOrElse(AbstractActor.scala:243) at akka.actor.Actor.aroundReceive(Actor.scala:513) at akka.actor.Actor.aroundReceive$(Actor.scala:511) at akka.actor.AbstractActor.aroundReceive(AbstractActor.scala:132) at akka.actor.ActorCell.receiveMessage(ActorCell.scala:527) at akka.actor.ActorCell.invoke(ActorCell.scala:496) at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:257) at akka.dispatch.Mailbox.run(Mailbox.scala:224) at akka.dispatch.Mailbox.exec(Mailbox.scala:234) at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) 2017-07-26 10:21:31,120 [ERROR] from akka.actor.ActorSystemImpl in application-akka.actor.default-dispatcher-8 - Uncaught error from thread [application-akka.actor.default-dispatcher-3]: null, shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled for ActorSystem[application] java.lang.ExceptionInInitializerError: null at io.ebean.Finder.db(Finder.java:101) at io.ebean.Finder.query(Finder.java:157) at modules.testregistration.RemoveTestRegistrationActor.onReceive(RemoveTestRegistrationActor.java:23) at akka.actor.UntypedAbstractActor$$anonfun$receive$1.applyOrElse(AbstractActor.scala:243) at akka.actor.Actor.aroundReceive(Actor.scala:513) at akka.actor.Actor.aroundReceive$(Actor.scala:511) at akka.actor.AbstractActor.aroundReceive(AbstractActor.scala:132) at akka.actor.ActorCell.receiveMessage(ActorCell.scala:527) at akka.actor.ActorCell.invoke(ActorCell.scala:496) at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:257) at akka.dispatch.Mailbox.run(Mailbox.scala:224) at akka.dispatch.Mailbox.exec(Mailbox.scala:234) at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) Caused by: java.lang.RuntimeException: java.lang.RuntimeException: DataSource user is null? at io.ebean.Ebean$ServerManager. (Ebean.java:164) at io.ebean.Ebean$ServerManager. (Ebean.java:124) at io.ebean.Ebean. (Ebean.java:118) ... 16 common frames omitted Caused by: java.lang.RuntimeException: DataSource user is null? at org.avaje.datasource.pool.ConnectionPool. (ConnectionPool.java:204) at org.avaje.datasource.Factory.createPool(Factory.java:12) at io.ebeaninternal.server.core.DefaultContainer.getDataSourceFromConfig(DefaultContainer.java:310) at io.ebeaninternal.server.core.DefaultContainer.setDataSource(DefaultContainer.java:265) at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:108) at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:79) at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:44) at io.ebean.EbeanServerFactory.create(EbeanServerFactory.java:55) at io.ebean.Ebean$ServerManager.getWithCreate(Ebean.java:201) at io.ebean.Ebean$ServerManager. (Ebean.java:159) ... 18 common frames omitted 2017-07-26 10:21:31,124 [INFO] from play.core.server.AkkaHttpServer in Thread-6 - Stopping server... 2017-07-26 10:21:31,154 [INFO] from akka.actor.CoordinatedShutdown in application-akka.actor.default-dispatcher-8 - Starting coordinated shutdown from JVM shutdown hook 2017-07-26 10:21:33,547 [INFO] from application in Thread-6 - Shutting down connection pool.
EDIT : it seems again that play-ebean bring the old play dependencies... 2.6.0 are presents instead of 2.6.2. Fixed with :
dependencyOverrides ++= Set(
"com.typesafe.play" % "play-jdbc_2.12" % "2.6.2",
"com.typesafe.play" % "play-jdbc-api_2.12" % "2.6.2",
"com.typesafe.play" % "play-jdbc-evolutions_2.12" % "2.6.2",
"com.typesafe.play" % "play-java-jdbc_2.12" % "2.6.2"
)
Try to use sbt update before sbt dist. Maybe that is a cleaner solution instead of the dependencyOverrides approach. That solved it for me. Reproducible on two environments with the same problem.
Try to use sbt update before sbt dist.
That's strange, I would have thought that dist already triggers an update...
I expected it too, but it seems the update is not performed. When you change the dependency versions the files are not copied into the bundle in the correct version (check the lib folder). Only manual dist update solves it. Reproducible with Play 2.6.x on two systems.
Been facing this for a while, and it happens really randomly too, but the above responses did not help me but instead, updating the sbt-play-ebean plugin made it work for me:
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "4.0.3")
in plugins.sbt
I think this should be reopened because these random fixes + it still happening randomly means it must be more then just dependency issues. I know its flaky and only reproducible for a selected few so I don't know how to approach it :/
Update: Specifically, doing sbt update and the dependencies override did not work for me
After banging my head against this issue for way too long, I have a theory. This is running play 2.6.7, but I think it probably applies to earlier versions as well.
The DataSource user is null? message gets printed when creating an EbeanServer. EbeanServer instances are created, and registered, through the static Ebean class.
The Play framework (at least in most examples) tries to create EbeanServers according to application config in EbeanDynamicEvolutions. This happens in the constructor, which is called by Guice (again, at least in most examples).
The thing that I think bites many people is that the examples, Ebean.getServer(name) is called in the constructor of Repository classes (e.g. CompanyRepository.java). This is again, called by Guice. The important thing here is that the getServer(name) method will try to create the ebean server if it does not exist.
Since, afaik, Guice has no pre-defined order when instantiating classes, the repository class might be created before the EbeanDynamicEvolutions instance. This leads to the repository class trying to create a server without any config, and thus the error. Since this depends on the rather arbitrary guice injection order + timing, a lot of the weird 'causes' in the comments above kind of makes sense.
I have been able to make this error stop happening by starting to use the Ebean.getServer(name) when accessing the database, instead of in repository constructors. E.g:
public class UserRepository {
private final String ebeanServer;
private final DatabaseExecutionContext executionContext;
@Inject
public UserRepository(EbeanConfig ebeanConfig, DatabaseExecutionContext executionContext) {
this.ebeanServer = ebeanConfig.defaultServer();
this.executionContext = executionContext;
}
public CompletionStage<Void> insert(User user) {
return supplyAsync(
() -> {
Ebean.getServer(ebeanServer).insert(user);
return null;
},
executionContext);
}
}
I believe that either the docs should be updated with this, or that the race condition at DI should be resolved somehow. I don't know which though :wink:
Reading up on the original reporter's issue, I think that my 'theory' was for a different bug than what was originally reported, but with the same symptoms. Might still be valid for others though.
In addition to @antonha answer, his solution didn't entirely work in my case. I'm posting this to help others with similar bug. (play 2.6.7, sbt-play-ebean 4.0.6, scala 2.12.4)
I think @antonha is right about the race condition, so I started ebean server from guice module.
My application.conf looks something like this:
db.default.driver = ...
db.default.url = ...
db.default.username = ...
db.default.password = ...
ebean.default = ["models.*"]
And here's the module:
public class Module extends AbstractModule {
private final Environment environment;
private final Config config;
public Module(
Environment environment,
Config config
) {
this.environment = environment;
this.config = config;
}
@Override
protected void configure() {
ServerConfig ebeanConfig = new ServerConfig();
DataSourceConfig db = new DataSourceConfig();
db.setDriver(config.getString("db.default.driver"));
db.setUsername(config.getString("db.default.username"));
db.setPassword(config.getString("db.default.password"));
db.setUrl(config.getString("db.default.url"));
ebeanConfig.setDefaultServer(true);
ebeanConfig.setDataSourceConfig(db);
EbeanServerFactory.create(ebeanConfig);
// ... rest of the bindings
}
}
Essentially it's not loading the EbeanDynamicEvolutions if you create your repository class like this you can make it work
private final EbeanServer ebeanServer;
private final DatabaseExecutionContext executionContext;
private final EbeanDynamicEvolutions ebeanDynamicEvolutions;
@Inject
public YourRepository(EbeanConfig ebeanConfig, EbeanDynamicEvolutions ebeanDynamicEvolutions, DatabaseExecutionContext executionContext) {
this.ebeanDynamicEvolutions = ebeanDynamicEvolutions;
this.ebeanServer = Ebean.getServer(ebeanConfig.defaultServer());
this.executionContext = executionContext;
}
Taken from in here :: https://github.com/playframework/play-ebean/issues/51
Can confirm, this still occurs with Play 2.6.11. Should be reopened.
@dimonok The error appeared again in my system after updating Play. But the advice by @rowanl solved the problem (for me).
This is a really huge problem that needs to be solved. Also occuring on Play 2.6.12 and play-ebean 4.1.0. Even in development mode sometimes. In development mode it helps by restarting the MySQL server and then compile the app again. After that it works. But that's not possible in a live environment.
Confirmed. It is still happening with Play 2.6.12 and play-ebean 4.1.0. Last solution from @rowanl worked, however it is still workaround.
Reopening since there are multiple reports against new versions of Play and play-ebean.
On my MacBook Pro 2017 my Play 2.6.12 App has the mentioned problems using play-ebean 4.1.0. On this machine it helped downgrading to 4.0. On a Linux machine it's the other way around. The same code showed the known problems, but on this machine upgrading to play-ebean 4.1.0 helped.
@GBeushausen thank you for the additional information.
Occurred again in production environment. Not reproducible on dev environment. @rowanl workaround is not working.
Play 2.6.12. sbt-play-ebean 4.0.6
ebean configuration:
allQuotedIdentifiers=true
namingconvention=io.ebean.config.MatchingNamingConvention
ebean.default = [
"com.company.product1.twitch.persistence.*",
...
]
Logs: https://gist.github.com/dimonok/eb59e16dd3e47e571876ddb174b6e755
Applied @rowanl's workaround to all of my repositories, now the app is starting again in production environment.
I just solved this error by change db.default.user to db.default.username. I hope this helps
I still have the error with play 2.6.13 and play ebean 4.1.0 (no errors with 4.0.6). But I have the error in development.
See my issue on the play-ebean repo: https://github.com/playframework/play-ebean/issues/145