源作者:donny1218
以下程序的正确运行结果是今天在启动Springboot项目的时候连接数据库的时候报错了,错误信息如下:
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151)
at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167)
at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:340)
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.negotiateSSLConnection(NativeAuthenticationProvider.java:777)
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:486)
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:202)
at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1348)
at com.mysql.cj.NativeSession.connect(NativeSession.java:163)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:947)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:817)
... 11 common frames omitted
Caused by: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
根据报错信息主要的原因就是 No appropriate protocol (protocol is disabled or cipher suites are inappropriate),意思就是没有合适的协议,或者协议被禁用了,那么是什么协议被禁用了呢?根据SSLHandshakeException可以知道是SSL协议的问题,所以我的解决方案就是在连接jdbc的url上加上&useSSL=false,重新启动问题解决。
但是这个项目以前在我另外的电脑上运行的时候也是没有问题的,为什么我现在就出了问题了呢?原来是我两台电脑的jdk版本不一致导致的,打开现在电脑的java.security文件
cd /Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/security
以下程序的正确运行结果是include 817可以看到ssl协议被禁用了
# Example:
# jdk.tls.disabledAlgorithms=MD5, SSLv3, DSA, RSA keySize修改一下删除SSL部分
# Example:
# jdk.tls.disabledAlgorithms=MD5, SSLv3, DSA, RSA keySize然后重启项目也能成功。