Slick 3.0连接到MySQL并启用了连接池

时间:2017-07-11 16:07:53

标签: scala slick-3.0

我有以下application.conf

mysql {
  driver = "com.mysql.jdbc.Driver"
  url = "jdbc:mysql://myserver:3306/mydb"
  user = "foo"
  password = "bar"
  keepAliveConnection = true
  connectionPool = enabled
}

当我Database.forConfig("mysql")时,我得到了一个例外

java.lang.ClassNotFoundException: enabled
        at java.lang.ClassLoader.findClass(ClassLoader.java:530)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at slick.util.ClassLoaderUtil$$anon$1.loadClass(ClassLoaderUtil.scala:17)
        at slick.jdbc.JdbcDataSource$.loadFactory$1(JdbcDataSource.scala:37)
        at slick.jdbc.JdbcDataSource$.forConfig(JdbcDataSource.scala:46)
        at slick.jdbc.JdbcBackend$DatabaseFactoryDef.forConfig(JdbcBackend.scala:288)
        at slick.jdbc.JdbcBackend$DatabaseFactoryDef.forConfig$(JdbcBackend.scala:285)
        at slick.jdbc.JdbcBackend$$anon$3.forConfig(JdbcBackend.scala:33)
        at com.abhi.CodeGen$.delayedEndpoint$com$abhi$CodeGen$1(CodeGen.scala:25)
        at com.abhi.CodeGen$delayedInit$body.apply(CodeGen.scala:15)
        at scala.Function0.apply$mcV$sp(Function0.scala:34)
        at scala.Function0.apply$mcV$sp$(Function0.scala:34)

如果我将配置更改为

mysql {
  driver = "com.mysql.jdbc.Driver"
  url = "jdbc:mysql://myserver:3306/mydb"
  user = "foo"
  password = "bar"
  keepAliveConnection = true
  connectionPool = disabled
}

然后一切正常。

但是,如果我尝试与连接池建立连接,为什么会收到此错误消息?

编辑:这是我的build.sbt

   "com.typesafe.slick" %% "slick" % "3.2.0",
   "com.typesafe.slick" %% "slick-codegen" % "3.2.0",
   "mysql" % "mysql-connector-java" % "5.1.38",
   "com.zaxxer" % "HikariCP" % "2.6.3"

1 个答案:

答案 0 :(得分:0)

对于某些具有池实现的jar,例如Hikari,你可能在classpath中没有依赖性。可能重复Setting connectionPool crashes Slick 3.0