阿里数据库连接池Druid 连接MySQL失败:javax.net.ssl.SSLHandshakeException: No appropriate protocol
程序员文章站
2022-06-12 17:14:21
...
昨天电脑蓝屏开不了机,一查是SSD坏了,还好项目这些在机械硬盘没有丢失。今天换了台新电脑,将项目复制过来,运行却出错了,Druid 连接不上MySQL,报了以下异常:
com.alibaba.druid.pool.DruidDataSource : create connection SQLException, url: jdbc:mysql://118.178.112:3306/test?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai, errorCode 0, state 08S01
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
...
Caused by: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
at sun.security.ssl.HandshakeContext.<init>(HandshakeContext.java:171)
at sun.security.ssl.ClientHandshakeContext.<init>(ClientHandshakeContext.java:101)
at sun.security.ssl.TransportContext.kickstart(TransportContext.java:238)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:394)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:373)
at com.mysql.cj.protocol.ExportControlled.performTlsHandshake(ExportControlled.java:315)
at com.mysql.cj.protocol.StandardSocketFactory.performTlsHandshake(StandardSocketFactory.java:188)
at com.mysql.cj.protocol.a.NativeSocketConnection.performTlsHandshake(NativeSocketConnection.java:99)
at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:352)
... 13 common frames omitted
百度一查,发现是jdk1.8版本导致SSL调用权限上有问题,新电脑装的jdk是jdk1.8.0_291,版本比较高。搜到的解决方法是:
找到jdk 1.8安装目录,找到C:\Program Files\Java\jre里面的lib\security 下面有个java.security。找到对应的SSLv3,删除掉,重启项目就好了。(删掉SSLv3就是允许SSL调用)
我找到Java安装目录下D:\Java\jdk1.8.0_291\jre\lib\security中的java.security文件,将对应的SSLv3删掉了,但运行还是出错。最后发现SSLv3后面有两个和它后缀一样的算法,将它们一起删掉后重启项目,成功解决问题。
删除后的文件如下图所示。
参考链接:https://blog.csdn.net/weixin_38111957/article/details/80577688