mssql server 2012数据库 jdk8 + springboot 项目 报错:SQL Server (SSL) encryption. Error: "The server selected protocol version TLS10 is not accepted by client preferences [TLS12]". ClientConnectionId
2023-04-13 11:01:39.727 [main] INFO com.alibaba.druid.pool.DruidDataSource:1003 - {dataSource-3,slave_2} inited 2023-04-13 11:01:39.846 [Druid-ConnectionPool-Create-116184677] ERROR com.alibaba.druid.pool.DruidDataSource:2699 - create connection SQLException, url: jdbc:sqlserver://192.168.99.131:1433;databaseName=database;characterEncoding=UTF-8;useUnicode=true&createDatabaseIfNotExist=true&useSSL=false;tinyInt1isBit=false;allowPublicKeyRetrieval=true;serverTimezone=Asia/Shanghai, errorCode 0, state 08S01 com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "The server selected protocol version TLS10 is not accepted by client preferences [TLS12]". ClientConnectionId:bc3a4e4f-83e0-4206-9a38-dafd7b44b940 at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:2670) at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1837) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2257) at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1921) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1762) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1077) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:623) at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:156) at com.alibaba.druid.filter.FilterAdapter.connection_connect(FilterAdapter.java:787) at com.alibaba.druid.filter.FilterEventAdapter.connection_connect(FilterEventAdapter.java:38) at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:150) at com.alibaba.druid.filter.FilterAdapter.connection_connect(FilterAdapter.java:787) at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:150) at com.alibaba.druid.filter.stat.StatFilter.connection_connect(StatFilter.java:218) at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:150) at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1598) at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1662) at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2697) Caused by: javax.net.ssl.SSLHandshakeException: The server selected protocol version TLS10 is not accepted by client preferences [TLS12] at sun.security.ssl.Alert.createSSLException(Unknown Source) at sun.security.ssl.Alert.createSSLException(Unknown Source) at sun.security.ssl.TransportContext.fatal(Unknown Source) at sun.security.ssl.TransportContext.fatal(Unknown Source) at sun.security.ssl.TransportContext.fatal(Unknown Source) at sun.security.ssl.ServerHello$ServerHelloConsumer.onServerHello(Unknown Source) at sun.security.ssl.ServerHello$ServerHelloConsumer.consume(Unknown Source) at sun.security.ssl.SSLHandshake.consume(Unknown Source) at sun.security.ssl.HandshakeContext.dispatch(Unknown Source) at sun.security.ssl.HandshakeContext.dispatch(Unknown Source) at sun.security.ssl.TransportContext.dispatch(Unknown Source) at sun.security.ssl.SSLTransport.decode(Unknown Source) at sun.security.ssl.SSLSocketImpl.decode(Unknown Source) at sun.security.ssl.SSLSocketImpl.readHandshakeRecord(Unknown Source) at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1767) ... 16 common frames omitted
报错解决:
创建文件custom.java.security 内容如下:
jdk.tls.disabledAlgorithms=SSLv3, RC4, DES, MD5withRSA, \ DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \ include jdk.disabled.namedCurves
和jar包在同一目录 如下图
执行命令:
java -jar "-Djava.security.properties=custom.java.security" project.jar
注意:1.命令-D参数必须加双引号
2. -D这条参数必须放在project.jar包前面。写在后面还是会报同样的错误。