Springboot 2.0无法访问SQL Server数据库

时间:2018-07-20 01:14:22

标签: java sql-server spring-boot hikaricp mssql-jdbc

请为我在最新版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".

我遵循了迁移guide,但没有成功。我还尝试了在Web上找到其他配置,但是没有任何解决该问题的方法。

这是由于Spring / Java版本引起的。

请注意application.properties中的数据源配置:

#CURRENT DATASOURCE CONFIG
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.url=jdbc:sqlserver://192.168.6.72;databaseName=WST
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://192.168.6.72;databaseName=WST
#spring.datasource.url=jdbc:sqlserver://192.168.6.72:1433/WST
#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

本周我一直在寻找原因。有关正确配置的一些建议会有所帮助。

谢谢。

1 个答案:

答案 0 :(得分:1)

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

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

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

Program Files \ 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方案。