一、問題簡述
拿到一個從其他地方拷貝而來的springboot項目項目,打算在宿舍電腦上部署。首先需要安裝相關依賴。
使用開發工具idea導入項目,右鍵–》open in terminal,在終端輸入mvn install爲安裝依賴的時候,出現以下報錯:
其中,控制檯的錯誤的主要信息:
Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.0.5.RELEASE
from/to nexus-aliyun (http://maven.aliyun.com/nexus/content/groups/public): sun.security.validator.ValidatorException
:
PKIX
path building failed: sun.security.provider.certpath.SunCertPathBuilderException:
unable to find valid certification path to requested target
and ‘parent.relativePath’ points
at no local POM @ line 5, column 10
項目pom.xml文件的報錯標紅提示:
請注意:本機maven鏡像使用的是阿里鏡像庫,在maven主目錄conf/setting.xml是這樣子配置(注意協議是http
):
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
在網上找了許久的解決方案,做了嘗試。遲遲未能解決問題,搗鼓了好長時間,終於得出瞭解決方案。
二、解決方案
第一步、修改maven阿里鏡像庫地址的協議:將http修改爲https
。
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>https://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
第二步、將阿里鏡像庫的證書加到信任證書庫裏面
溫馨提示:建議使用Firefox流浪器導出後綴爲.crt的證書文件
1、通過chrome瀏覽器下載證書到本地
(1)在Chrome中打開鏈接,點擊左邊“小鎖頭”圖標後出現彈窗,再點擊“證書”。
(2)點擊“詳細信息”tab,點擊“複製到文件”,選擇本機某個位置,點擊“保存”。
此處,我保存在d:\ali_maven.cer
2、通過證書添加到java信任證書庫
本機管理員打開cmd,切換到:{java安裝根目錄}\jre\lib\security
運行如下命令keytool -import -alias cacerts -keystore cacerts -file d:\ali_maven.cer
輸入默認密碼:changeit
,這是java中cacerts證書庫的默認密碼。
輸入Y,表示信任此證書,至此,阿里鏡像證書已成功添加至java信任證書庫
三、總結提升
該異常是客戶端對服務器的證書認證的時候出錯了,解決方案把服務器證書加到信任證書庫裏面
把該證書導入java中的cacerts證書庫裏。