I am migrating my app from play 2.3 to 2.4.
In my 2.3 app in my GlobalSettings, I had to access the database using slick to create a postgres database function.
Since GlobalSettings is deprecated in 2.4, the alternative is to use Eager Bindings:
https://www.playframework.com/documentation/2.4.x/ScalaDependencyInjection#Eager-bindings
like this:
class MyModule extends AbstractModule {
def configure() = {
db.withSession { implicit ss =>
StaticQuery.update("""CREATE OR REPLACE FUNCTION ... """).execute
}
}
}
But this gives me the error:
java.lang.ExceptionInInitializerError:
core.includes$.<init>(includes.scala:14)
core.includes$.<clinit>(includes.scala)
Application$$anonfun$configure$1.apply(Application.scala:17)
Application$$anonfun$configure$1.apply(Application.scala:15)
scala.slick.backend.DatabaseComponent$DatabaseDef$class.withSession(DatabaseComponent.scala:34)
scala.slick.jdbc.JdbcBackend$DatabaseFactoryDef$$anon$4.withSession(JdbcBackend.scala:61)
modules.jdbc.Database$$anonfun$withSession$1.apply(Database.scala:14)
modules.jdbc.Database$$anonfun$withSession$1.apply(Database.scala:14)
Application.configure(Application.scala:15)
com.google.inject.AbstractModule.configure(AbstractModule.java:62)
com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:340)
com.google.inject.spi.Elements.getElements(Elements.java:110)
com.google.inject.util.Modules$OverrideModule.configure(Modules.java:177)
com.google.inject.AbstractModule.configure(AbstractModule.java:62)
com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:340)
com.google.inject.spi.Elements.getElements(Elements.java:110)
com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:138)
com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104)
com.google.inject.Guice.createInjector(Guice.java:96)
com.google.inject.Guice.createInjector(Guice.java:73)
com.google.inject.Guice.createInjector(Guice.java:62)
play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:126)
play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:93)
play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
Does anyone have a clue on how I can fix this? Thanks.