天天看點

【Azure Spring Cloud】使用azure-spring-boot-starter-storage來上傳檔案報錯: java.net.UnknownHostException: xxxxxxxx.blob.core.windows.net: Name or service not known

問題描述

使用 azure-spring-boot-starter-storage 來上傳檔案到 Storage Blob中,并把應用部署到Azure 中國區的Spring Cloud服務後,調用上傳檔案的接口報錯:  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導緻,在中國區,正确的Blob Endpoint為:xxxxxxxx.blob.core.chinacloudapi.cn

根據檢視官方文檔,對 azure storage的spring boot引用的storage 依賴名稱為 com.azure.spring:azure-spring-boot-starter-storage,而目前錯誤的應用中引用的是 com.microsoft.azure: spring-starter-azure-storage

【Azure Spring Cloud】使用azure-spring-boot-starter-storage來上傳檔案報錯: java.net.UnknownHostException: xxxxxxxx.blob.core.windows.net: Name or service not known

根據文檔建議修改後,上傳檔案問題“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

當在複雜的環境中面臨問題,格物之道需:濁而靜之徐清,安以動之徐生。 雲中,恰是如此!

繼續閱讀