gpt4 book ai didi

java - Springboot 2.0无法访问SQL Server数据库

转载 作者:行者123 更新时间:2023-11-30 06:05:26 24 4
gpt4 key购买 nike

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

开发环境:

-Spring Boot 2.0.3.RELEASE

-JDK/JRE 10 (jdk-10.0.1)

-IDE:Spring工具套件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但没有成功。我还尝试了在网络上找到的不同配置,但没有解决此问题。

出现这种情况是因为 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=XXXXXX
#spring.datasource.password=XXXXXX
#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

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

提前致谢。

最佳答案

这是一个 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 方案。

关于java - Springboot 2.0无法访问SQL Server数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51433759/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com