监控sqlserver数据库报错 The server selected protocol version TLS10 is not accepted by client preferences [TLS12]

2025-01-26 10:38:28.007 [http-nio-9999-exec-4] ERROR com.wgcloud.util.jdbc.ConnectionUtil - 连接数据库错误
org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is 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 [TLS13, TLS12]". ClientConnectionId:8dcc9be4-f61d-4ff9-9a5f-a86242205249
......   
Caused by: javax.net.ssl.SSLHandshakeException: The server selected protocol version TLS10 is not accepted by client preferences [TLS13, TLS12]
......
原因描述:SQLServer 服务器只接受 TLS1.0,但是客户端给的是 TLS1.2
解决方法如下:
打开文件:JAVA_HOME\jre\lib\security\java.security,搜索关键词jdk.tls
可以找到配置项:jdk.tls.disabledAlgorithms(jdk不生效的算法配置)里面有TLSv1, 也就是说 TSL1.0版本不让用了
这样就解释了为啥会出现问题
以下三种解决方法,任选其一即可
1. 把 jdk.tls.disabledAlgorithms 配置项中 TLSv1 删除,这样 TLS1.0 就可以使用了
2. 把 jdk.tls.disabledAlgorithms 配置项注释掉或者删掉
3. 如果嫌麻烦可以直接把 java.security 文件删了,问题可以解决,但是会不会出现其他问题就不得而知了,慎重使用