解決SpringBoot連接SqlServer出現(xiàn)的問題
SpringBoot連接SqlServer出現(xiàn)問題
“Encrypt”屬性設(shè)置為“true”且 “trustServerCertificate”屬性設(shè)置為“false”
但驅(qū)動程序無法使用安全套接字層 (SSL) 加密與 SQL Server 建立安全連接:
錯誤:PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target。
通過yml配置時出現(xiàn)了上方的問題
spring: datasource: driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver username: sa password: 123456 url: jdbc:sqlserver://localhost:1433;databaseName=xxx;
這時候注意你的sql語句不能寫錯了,不然也會報錯
在數(shù)據(jù)庫名后面 ;trustServerCertificate=true 加上這個就可以了
Java連接SqlServer報服務(wù)端僅支持TLS10
報錯
Invocation of init method failed; 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]
通過查閱網(wǎng)上資料大部分說原因是Java認(rèn)為TLSv1不太安全所以在java.security中通過jdk.tls.disabledAlgorithms配置禁用了TLSv1, TLSv1.1,導(dǎo)致Java應(yīng)用作為SQLServer客戶端連接服務(wù)時使用的TLS13, TLS12協(xié)議,但是SQLServer服務(wù)端可能版本比較老或者配置了僅支持TLS10導(dǎo)致報上述錯誤
原因是最近更新了jdk8的小版本導(dǎo)致Java的安全文件變更了
處理方式
修改基礎(chǔ)鏡像中的/usr/java/latest/jre/lib/security/java.security文件內(nèi)容,替換成之前的內(nèi)容
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
SpringBoot 集成JUnit5的詳細(xì)操作過程
JUnit5是最新的Java單元測試框架,提供了靈活的測試支持,它由JUnit Platform、JUnit Jupiter和JUnit Vintage組成,支持不同環(huán)境下的測試運行,SpringBoot從2.2版本開始默認(rèn)支持JUnit5,本文介紹了SpringBoot 集成JUnit5的相關(guān)知識,感興趣的朋友跟隨小編一起看看吧2024-10-10Spring Boot使用Druid和監(jiān)控配置方法
Druid是Java語言中最好的數(shù)據(jù)庫連接池,并且能夠提供強大的監(jiān)控和擴展功能。下面來說明如何在 Spring Boot 中配置使用Druid2017-04-04