我正试图让这三个人一起工作,但不能。缺乏光滑的文档。我有针对Typesafe配置的application.conf设置,如下所示:
mysql = {
url = "jdbc:mysql://localhost/slickdb"
slick.driver=scala.slick.driver.MySQLDriver
driver=com.mysql.cj.jdbc.Driver
properties = {
user = root
password = null
}
connectionPool = true
keepAliveConnection = true
}
和build.sbt相关的依赖项:
libraryDependencies ++= Seq(
...
"org.eclipse.jetty" % "jetty-webapp" % "9.2.15.v20160210" % "container",
"javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided",
"com.typesafe.slick" %% "slick" % "3.2.0",
"com.typesafe.slick" %% "slick-hikaricp" % "3.2.0",
"mysql" % "mysql-connector-java" % "latest.integration"
...
)
并尝试编译一个简单的DAO
import slick.jdbc.MySQLProfile.api._
class testDAO {
private val db = Database.forConfig("mysql")
}
但是SBT编译器抛出了这个异常:
java.lang.ClassNotFoundException: true
at java.lang.ClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
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)
我也尝试过:
import slick.jdbc.MySQLProfile.api._
import slick.basic.DatabaseConfig
class testDAO {
val dbConfig = DatabaseConfig.forConfig("mysql")
}
但我得到另一个例外:
slick.SlickException: Configured profile com.mysql.cj.jdbc.Driver does not conform to requested profile scala.runtime.Nothing$
at slick.basic.DatabaseConfig$.forConfig(DatabaseConfig.scala:99)
at com.unamur.service.testDAO.<init>(CatDAO.scala:18)
at com.unamur.app.TestServlet.<init>(TestServlet.scala:11)
at ScalatraBootstrap.init(ScalatraBootstrap.scala:7)
有人有想法吗?提前谢谢。
答案 0 :(得分:3)
connectionPool = true
是问题所在。您需要提供实施,{{1}}或其他。