Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Play 2.8.2, slick.dbs.default.profile config throws ClassNotFound exception when using custom Profile #572

Open
alternegro opened this issue Jul 23, 2020 · 4 comments
Labels

Comments

@alternegro
Copy link

alternegro commented Jul 23, 2020

Corresponding Slick PG Issue

Play Slick Version

5.0.0

Play Version

2.8.2

API

Scala 2.13.2

Operating System

macOS 10.15.5

JDK

java version 11

Library Dependencies

"com.github.tminglei" %% "slick-pg" % "0.19.0"
"org.postgresql" % "postgresql" % "42.2.13"
"com.typesafe.slick" %% "slick" % "3.3.2"
"com.typesafe.slick" %% "slick-hikaricp" % "3.3.2"
"com.typesafe.play" %% "play-slick" % "5.0.0"
"com.typesafe.play" %% "play-slick-evolutions" % "5.0.0"

Expected Behavior

  1. Application should connect to database as it does in version 2.8.1 when configured like below in application.conf
slick {
  dbs {
    default {
      profile = "io.mydomain.persistence.PostgresProfile$"
      db {
        driver = "org.postgresql.Driver"
        url = "jdbc:postgresql://localhost:5432/thedatabase"
        user = "theuser"
        password = "thepassword"
      }
    }
  }
}
package io.mydomain.persistence

import com.github.tminglei.slickpg._
import slick.driver.JdbcProfile
import slick.basic.Capability
import play.api.libs.json.{Format, Json, JsValue}

trait PostgresProfile
  extends ExPostgresProfile
                          with PgArraySupport
                          with PgDate2Support
                          with PgRangeSupport
                          with PgHStoreSupport
                          with PgPlayJsonSupport
                          with PgSearchSupport
                          with PgPostGISSupport
                          with PgNetSupport
                          with PgLTreeSupport {
  def pgjson = "jsonb" 

  override val api = MyAPI

  object MyAPI extends API with ArrayImplicits
                           with DateTimeImplicits
                           with JsonImplicits
                           with NetImplicits
                           with LTreeImplicits
                           with RangeImplicits
                           with HStoreImplicits
                           with SearchImplicits
                           with SearchAssistants {
    implicit val strListTypeMapper = new SimpleArrayJdbcType[String]("text").to(_.toList)
    implicit val playJsonArrayTypeMapper =
      new AdvancedArrayJdbcType[JsValue](pgjson,
        (s) => utils.SimpleArrayUtils.fromString[JsValue](Json.parse(_))(s).orNull,
        (v) => utils.SimpleArrayUtils.mkString[JsValue](_.toString())(v)
      ).to(_.toList)
  }
}

object PostgresProfile extends PostgresProfile

Actual Behavior

  1. Fails to connect to database when
play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [default]]
        at play.api.Configuration$.configError(Configuration.scala:155)
        at play.api.Configuration.reportError(Configuration.scala:394)
        at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.create(SlickApi.scala:99)
        at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.get$lzycompute(SlickApi.scala:87)
        at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.get(SlickApi.scala:86)
        at play.api.db.slick.DefaultSlickApi.dbConfig(SlickApi.scala:70)
        at TestApp.dbConfig$lzycompute(Loader.scala:36)
        at TestApp.dbConfig(Loader.scala:36)
        at TestApp.signUpCodesService$lzycompute(Loader.scala:42)
        at TestApp.signUpCodesService(Loader.scala:42)
Caused by: slick.SlickException: Error getting instance of profile "io.mydomain.persistence.PostgresProfile$"
        at slick.basic.DatabaseConfig$.forConfig(DatabaseConfig.scala:95)
        at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.create(SlickApi.scala:95)
        at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.get$lzycompute(SlickApi.scala:87)
        at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.get(SlickApi.scala:86)
        at play.api.db.slick.DefaultSlickApi.dbConfig(SlickApi.scala:70)
        at TestApp.dbConfig$lzycompute(Loader.scala:36)
        at TestApp.dbConfig(Loader.scala:36)
        at TestApp.signUpCodesService$lzycompute(Loader.scala:42)
        at TestApp.signUpCodesService(Loader.scala:42)
        at TestApp.signUpCodesController$lzycompute(Loader.scala:55)
Caused by: java.lang.ClassNotFoundException: io.mydomain.persistence.PostgresProfile$
        at java.base/java.lang.ClassLoader.findClass(ClassLoader.java:719)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
        at slick.util.ClassLoaderUtil$$anon$1.loadClass(ClassLoaderUtil.scala:17)
        at slick.basic.DatabaseConfig$.forConfig(DatabaseConfig.scala:92)
        at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.create(SlickApi.scala:95)
        at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.get$lzycompute(SlickApi.scala:87)
        at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.get(SlickApi.scala:86)
        at play.api.db.slick.DefaultSlickApi.dbConfig(SlickApi.scala:70)
        at TestApp.dbConfig$lzycompute(Loader.scala:36)

Reproducible Test Case

The issue goes away when I simply change the Play plugin version from 2.8.2 to 2.8.1

@alternegro alternegro changed the title In Play 2.8.2, slick.dbs.default.profile config throws ClassNotFound exception When using custom Profile In Play 2.8.2, slick.dbs.default.profile config throws ClassNotFound exception when using custom Profile Jul 23, 2020
@Daxten
Copy link

Daxten commented Aug 11, 2020

I have the same problem in 2.8.1 somtimes on recompiles, also using akka-persistence with the normal jdbc driver in the same application.

restarting sbt fixes it. It seems to always happen if akka-persistence starts up earlier then the migration I think?

@alternegro
Copy link
Author

I have the same problem in 2.8.1 somtimes on recompiles, also using akka-persistence with the normal jdbc driver in the same application.

restarting sbt fixes it. It seems to always happen if akka-persistence starts up earlier then the migration I think?

I have several apps using 2.8.1, but I’m yet to encounter the issue in them. The issue shows up EVERY time I’ve tried 2.8.2. I’m working on an Akka application write now, I’ll look out for the issue there as well. I cross posted this issue in slick-pg and others have reported seeing it.

@arteme
Copy link

arteme commented Aug 12, 2020

I think it would be useful to link the issues for completeness. This and tminglei/slick-pg#484.

@alternegro
Copy link
Author

This appears to be an issue with Classloading in Play Dev.mode. Adding my custom profile as an unmanaged dependency solves the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants