没有加载 HikariCP 驱动程序的 slick 3.0.0 - IllegalAccessException:AbstractHikariConfig 无法访问带有修饰符的成员 "private"

slick 3.0.0 with HikariCP driver not loaded - IllegalAccessException: AbstractHikariConfig can not access a member with modifiers "private"

我正在尝试将 tminglei/slick-pg v9.0.0 与 slick 3.0.0 一起使用,我得到一个 IllegalAccessException:

akka.actor.ActorInitializationException: exception during creation
    at akka.actor.ActorInitializationException$.apply(Actor.scala:166) ~[akka-actor_2.11-2.3.11.jar:na]
    ...
Caused by: java.lang.RuntimeException: driverClassName specified class 'com.github.tminglei.MyPostgresDriver$' could not be loaded
    at com.zaxxer.hikari.AbstractHikariConfig.setDriverClassName(AbstractHikariConfig.java:370) ~[HikariCP-java6-2.3.8.jar:na]
    at slick.jdbc.HikariCPJdbcDataSource$$anonfun$forConfig.apply(JdbcDataSource.scala:145) ~[slick_2.11-3.0.0.jar:na]
    at slick.jdbc.HikariCPJdbcDataSource$$anonfun$forConfig.apply(JdbcDataSource.scala:145) ~[slick_2.11-3.0.0.jar:na]
    at scala.Option.map(Option.scala:146) ~[scala-library-2.11.7.jar:na]
    at slick.jdbc.HikariCPJdbcDataSource$.forConfig(JdbcDataSource.scala:145) ~[slick_2.11-3.0.0.jar:na]
    at slick.jdbc.HikariCPJdbcDataSource$.forConfig(JdbcDataSource.scala:135) ~[slick_2.11-3.0.0.jar:na]
    at slick.jdbc.JdbcDataSource$.forConfig(JdbcDataSource.scala:35) ~[slick_2.11-3.0.0.jar:na]
    at slick.jdbc.JdbcBackend$DatabaseFactoryDef$class.forConfig(JdbcBackend.scala:223) ~[slick_2.11-3.0.0.jar:na]
    at slick.jdbc.JdbcBackend$$anon.forConfig(JdbcBackend.scala:33) ~[slick_2.11-3.0.0.jar:na]
    ...
Caused by: java.lang.IllegalAccessException: Class com.zaxxer.hikari.AbstractHikariConfig can not access a member of class com.github.tminglei.MyPostgresDriver$ with modifiers "private"
    at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:109) ~[na:1.7.0_79]
    at java.lang.Class.newInstance(Class.java:373) ~[na:1.7.0_79]
    at com.zaxxer.hikari.AbstractHikariConfig.setDriverClassName(AbstractHikariConfig.java:366) ~[HikariCP-java6-2.3.8.jar:na]
    ... 43 common frames omitted

HikariCP 是 slick 3.0.0 中的默认连接池

我已经定义了驱动程序 class 很像 example:

trait MyPostgresDriver extends ExPostgresDriver with PgArraySupport
  with PgEnumSupport
  with PgRangeSupport
  with PgHStoreSupport
  with PgSearchSupport{

  override val api = new MyAPI {}

  //////
  trait MyAPI extends API
  with ArrayImplicits
  with RangeImplicits
  with HStoreImplicits
  with SearchImplicits
  with SearchAssistants

}

object MyPostgresDriver extends MyPostgresDriver

我的数据库配置非常简单[类型安全配置的摘录如下]:

slick.dbs.default {

  driver="com.github.tminglei.MyPostgresDriver$"

  db {
    driver="org.postgresql.Driver"

    url="jdbc:postgresql://hostname:port/dbname"
    user=user
    password="pass"
  }
}

它似乎不应该工作,然而...

我应该以某种方式更改我的驱动程序 class 吗?还是别的什么?

注意:从我正在使用的堆栈跟踪中可以看出

  1. Java1.7.0_79
  2. Scala 2.11.7
  3. akka 2.3.11(我共享 slick 和 akka 的配置实例)
  4. 光滑 3.0.0
  5. HikariCP-java62.3.8
  6. tminglei的slick-pg_core0.9.0

最后, 通过 Class.class 处的 jdk 代码调试时(反编译第 143 行)

 Constructor tmpConstructor1 = this.cachedConstructor; 

我得到以下(toString'ed)值(如 intellij 所示):

private com.github.tminglei.MyPostgresDriver$()

这能说明问题吗?如果是,我该如何解决?


编辑

我已经用现有的 PostgresDriver 替换了自定义驱动程序配置,如下所示:

slick.dbs.default {

  driver="slick.driver.PostgresDriver$"

  db {
    driver="org.postgresql.Driver"

    url="jdbc:postgresql://hostname:port/dbname"
    user=user
    password="pass"
  }
}

错误相同:

akka.actor.ActorInitializationException: exception during creation
    ...
Caused by: java.lang.RuntimeException: driverClassName specified class 'slick.driver.PostgresDriver$' could not be loaded
    ... 
Caused by: java.lang.IllegalAccessException: Class com.zaxxer.hikari.AbstractHikariConfig can not access a member of class slick.driver.PostgresDriver$ with modifiers "private"

我遇到了类似的问题。

我认为您使用的是 Database.forConfig("slick.dbs.default"),但您的配置文件是 DatabaseConfig 格式。

改为尝试使用:

val dbConfig: DatabaseConfig[PostgresDriver] = DatabaseConfig.forConfig("slick.dbs.default")
val db = dbConfig.db