【Azure Developer】Springboot 集成 中国区的Key Vault 报错 AADSTS90002: Tenant 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' not found
问题描述
Springboot 集成azure keyvault 报错,代码参考的官方文档:https://docs.microsoft.com/en-us/azure/developer/java/spring-framework/configure-spring-boot-starter-java-app-with-azure-key-vault。 在运行时候,报错:Caused by: com.microsoft.aad.msal4j.MsalServiceException: AADSTS90002: Tenant 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' not found. Check to make sure you have the correct tenant ID and are signing into the correct cloud. Check with your subscription administrator, this may happen if there are no active subscriptions for the tenant.
问题解答
通常遇见 tenant not found问题,就是Azure的环境设置不对引起的,因为参考的文档为Global Azure的代码,所以在配置Key Vault信息的时候,默认指向的是Global的Azure环境。
如在文章中的 “Add Key Vault configuration” 部署,只有 client-id, client-secret, endpoint, tenant 信息,没有配置 cloud-type=AZURE_CHINA 的信息,所以默认指向为Global Azure,所以存在China Azure中的Tenant当然在Global Azure中是无法发现的。
解决办法
在 src/main/resources/application.properties 配置文件中,添加 spring.cloud.azure.keyvault.secret.property-sources[0].profile.cloud-type=AZURE_CHINA
如下图:
spring.cloud.azure.keyvault.secret.property-sources[0].credential.client-id=<your client ID> spring.cloud.azure.keyvault.secret.property-sources[0].credential.client-secret=<your client key> spring.cloud.azure.keyvault.secret.property-sources[0].endpoint=https://contosokv.vault.azure.cn/ spring.cloud.azure.keyvault.secret.property-sources[0].profile.tenant-id=<your tenant ID> spring.cloud.azure.keyvault.secret.property-sources[0].profile.cloud-type=AZURE_CHINA
即可成功解决问题!
参考资料
Read a secret from Azure Key Vault in a Spring Boot application : https://learn.microsoft.com/en-us/azure/developer/java/spring-framework/configure-spring-boot-starter-java-app-with-azure-key-vault#add-key-vault-configuration-to-the-app
当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· NetPad:一个.NET开源、跨平台的C#编辑器
· PowerShell开发游戏 · 打蜜蜂