【Azure Spring Cloud】使用azure-spring-boot-starter-storage來上傳文件報錯: java.net.UnknownHostException

問題描述

使用 azure-spring-boot-starter-storage 來上傳文件到 Storage Blob中,并把應(yīng)用部署到Azure 中國區(qū)的Spring Cloud服務(wù)后,調(diào)用上傳文件的接口報錯: java.net.UnknownHostException: xxxxxxxx.blob.core.windows.net: Name or service not known

使用的依賴為:

<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>spring-starter-azure-storage</artifactId>
    <version>1.2.8</version>
</dependency>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.5.RELEASE</version>
    <relativePath/>
</parent>

問題解決

從錯誤來分析,這是使用到了SDK中默認Global Azure Storage的Endpoint導(dǎo)致,在中國區(qū),正確的Blob Endpoint為:xxxxxxxx.blob.core.chinacloudapi.cn

根據(jù)查看官方文檔,對 azure storage的spring boot引用的storage 依賴名稱為 com.azure.spring:azure-spring-boot-starter-storage,而當前錯誤的應(yīng)用中引用的是 com.microsoft.azure: spring-starter-azure-storage


image

根據(jù)文檔建議修改后,上傳文件問題“Name not known”得以解決。

參考資料

Spring Boot Starter for Azure Storage: https://docs.microsoft.com/en-us/azure/developer/java/spring-framework/configure-spring-boot-starter-java-app-with-azure-storage

當在復(fù)雜的環(huán)境中面臨問題,格物之道需:濁而靜之徐清,安以動之徐生。 云中,恰是如此!

分類: 【Azure Spring Cloud】

標簽: Azure Developer, Azure Spring Cloud, blob.core.windows.net: Name or service not known

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容