問題描述
使用 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

根據(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 Developer, Azure Spring Cloud, blob.core.windows.net: Name or service not known