首页 > 解决方案 > Springboot 2.0 无法访问 SQL Server 数据库

问题描述

请帮助解决我在最新的 Springboot (2.0.3.RELEASE) 上遇到的问题我在尝试访问数据库时遇到以下错误。在迁移到提到的 Springboot 和 Java 10 版本之前它正在工作。

开发环境:

-Spring Boot 2.0.3.RELEASE

-JDK/JRE 10 (jdk-10.0.1)

-IDE:Spring Tool Suite 3.9.5.RELEASE

错误:

2018-07-19 20:24:37.524 ERROR 12532 --- [  restartedMain] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Exception during pool initialization.

com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "SQL Server did not return a response. The connection has been closed. ClientConnectionId:33a45785-248c-4b57-ba29-f8802ddd8b25".

Caused by: java.io.IOException: SQL Server did not return a response. The connection has been closed. ClientConnectionId:33a45785-248c-4b57-ba29-f8802ddd8b25

org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta-data; nested exception is 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: "SQL Server did not return a response. The connection has been closed. ClientConnectionId:33a45785-248c-4b57-ba29-f8802ddd8b25".

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "SQL Server did not return a response. The connection has been closed. ClientConnectionId:33a45785-248c-4b57-ba29-f8802ddd8b25".

我遵循了迁移指南,但没有成功。我也尝试了在网上找到的不同配置,但没有解决这个问题。

这是因为 Spring / Java 版本而发生的。

注意 application.properties 中的 DataSource 配置:

#CURRENT DATASOURCE CONFIG
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.url=jdbc:sqlserver://xxx.xxx.x.xx;databaseName=XXX
spring.datasource.hikari.username=user
spring.datasource.hikari.password=password
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto = none
spring.jpa.show-sql=true

#FOLLOWING CONFIG ARE JUST FOR REFERENCE. I TRIED THEM AS PER BLOGS 
#spring.datasource.hikari.dataSourceClassName=com.microsoft.sqlserver.jdbc.SQLServerDataSource
#spring.datasource.url=jdbc:sqlserver://XXX.XXX.X.XX;databaseName=XXX
#spring.datasource.url=jdbc:sqlserver://XXX.XXX.X.XX:1433/XXX
#spring.datasource.type=
#spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource
#spring.datasource.tomcat.max-active=1
#spring.datasource.username=wstapp
#spring.datasource.password=wstapp@test
#spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
#spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDataSource
#spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
#spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
#spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

这周我一直在寻找一个理由。有关正确配置的一些建议会有所帮助。

提前致谢。

标签: javasql-serverspring-boothikaricpmssql-jdbc

解决方案


这是一个 MSSQL-JDBC 问题。答案是:Nitin Vavdiya 为我指明了正确的方向。

我在这里找到了“解决方案”:https ://github.com/Microsoft/mssql-jdbc/issues/719

我刚刚修改了JRE安装文件夹中的java.security文件,并从文件中的jdk.tls.disabledAlgorithms中删除了值: 3DES_EDE_CBC

程序文件\Java\"JRE 版本"\lib\security

以下是帮助我的确切答案:

为了提高 SSL/TLS 连接的强度,已通过 jdk.tls.disabledAlgorithms 安全属性在 JDK 中的 SSL/TLS 连接中禁用 3DES 密码套件。(http://www.oracle.com/technetwork/java/javase/8u171-relnotes-4308888.html

更改 java.security 并从 jdk.certpath.disabledAlgorithms 中删除 3DES_EDE_CBC 后一切正常。我不确定在 SQLServer 配置中需要更改哪些内容以禁用 3DES 作为 SSL 方案。


推荐阅读