我正在尝试使用Slick和HikariCP设置SSL加密。这是conf:
mysqldb = {
dataSourceClass = "com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
initializationFailFast = false
properties {
user = "ssl_user"
password = "root"
databaseName = "ssl_db"
serverName = "localhost"
useUnicode = true
characterEncoding = UTF-8
sslMode="VERIFY_IDENTITY"
javax.net.ssl.trustStore="/home/ec2-user/rds-combined-ca-bundle.pem"
javax.net.ssl.trustStorePassword=""
}
connectionTimeout = 10000
numThreads = 10
maxConnections = 10
minConnections = 4
queueSize =10000
}
创建连接的代码:
import slick.jdbc.MySQLProfile.api._
val connectionPool = Database.forConfig(s"mysqldb")
val session = connectionPool.createSession()
但是,它抛出错误:
Exception in thread "main" java.lang.RuntimeException: Property sslMode does not exist on target class com.mysql.jdbc.jdbc2.optional.MysqlDataSource
at com.zaxxer.hikari.util.PropertyElf.setProperty(PropertyElf.java:131)
at com.zaxxer.hikari.util.PropertyElf.lambda$setTargetFromProperties$0(PropertyElf.java:57)
at java.util.Hashtable.forEach(Hashtable.java:879)
at com.zaxxer.hikari.util.PropertyElf.setTargetFromProperties(PropertyElf.java:52)
at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:333)
at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:109)
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:108)
at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:81)
at slick.jdbc.hikaricp.HikariCPJdbcDataSource$.forConfig(HikariCPJdbcDataSource.scala:92)
at slick.jdbc.hikaricp.HikariCPJdbcDataSource$.forConfig(HikariCPJdbcDataSource.scala:21)
at slick.jdbc.JdbcDataSource$.forConfig(JdbcDataSource.scala:47)
at slick.jdbc.JdbcBackend$DatabaseFactoryDef.forConfig(JdbcBackend.scala:341)
at slick.jdbc.JdbcBackend$DatabaseFactoryDef.forConfig$(JdbcBackend.scala:337)
at slick.jdbc.JdbcBackend$$anon$1.forConfig(JdbcBackend.scala:32
at scala.Function0.apply$mcV$sp(Function0.scala:39)
at scala.Function0.apply$mcV$sp$(Function0.scala:39)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
at scala.App.$anonfun$main$1(App.scala:73)
at scala.App.$anonfun$main$1$adapted(App.scala:73)
at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:553)
at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:551)
at scala.collection.AbstractIterable.foreach(Iterable.scala:921)
at scala.App.main(App.scala:73)
at scala.App.main$(App.scala:71)
任何帮助将不胜感激。
sslMode
是com.mysql.jdbc.jdbc2.optional.MysqlDataSource
的不受支持的配置属性。根据文档,它确实支持useSSL=true/false
。默认情况下,对于MySQL 5.6.26+或5.7.6+,此选项设置为true,否则会失败。
您可以在这里找到所有与安全性相关的配置参数:https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html。
如果您想验证MySQL服务器的证书,请查看verifyServerCertificate
属性的说明。
还有一个页面,详细介绍如何使用jdbc2驱动程序建立与MySQL的安全连接:https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-using-ssl.html