【问题标题】:How to set up azure keyvault for spring boot app?如何为 Spring Boot 应用程序设置 azure keyvault?
【发布时间】:2022-08-18 19:07:45
【问题描述】:

由于我们使用的是旧版本的 azure keyvault (azure-keyvault-secrets-spring-boot-starter 2.2.1),因此发生了一些依赖项不兼容,但它已更新,我们正在将其升级到 azure-spring-boot-starter- keyvault-secrets 4.0.0.现在 keyvault 没有被连接可能是因为 application.yml keyvault 配置的语法错误。

这是之前使用 2.2.1 版本时的情况:

azure:
  keyvault:
    uri: ${uri}
    client-id: ${clientId}
    client-key: ${clientKey}
    token-acquire-timeout-seconds: 120

这就是我们现在正在尝试的方式,但它没有连接。

spring:
  cloud:
    azure:
      keyvault:
        secret:
          property-sources:
            uri: ${uri}
            client-id: ${clientId}
            client-key: ${clientKey}
            token-acquire-timeout-seconds: 120

此 azure keyvault 版本配置的正确语法是什么?

    标签: java spring spring-boot azure azure-keyvault


    【解决方案1】:

    spring-cloud-azure-starter-keyvault-certificates 的以下依赖项添加到pom.xml 文件中。

    <properties>
            <version.spring.cloud.azure>4.3.0</version.spring.cloud.azure> 
    </properties>
    <dependencies>
          <dependency>
                 <groupId>com.azure.spring</groupId>
                 <artifactId>spring-cloud-azure-starter-keyvault-secrets</artifactId>
          </dependency> 
    </dependencies> 
    <dependencyManagement>
             <dependencies>
                 <dependency>
                     <groupId>com.azure.spring</groupId>
                     <artifactId>spring-cloud-azure-dependencies</artifactId>
                     <version>${version.spring.cloud.azure}</version>
                     <type>pom</type>
                     <scope>import</scope>
                 </dependency>
       </dependencies> 
    </dependencyManagement>
    
    • 转到-->src/main/resources/application.properties文件并添加以下属性以配置 azure 密钥库以链接到 Spring Boot 应用程序:
        spring.cloud.azure.keyvault.secret.property-source-enabled=true
        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.net/
        spring.cloud.azure.keyvault.secret.property-sources[0].profile.tenant-id=<your tenant ID>
    

    以上参考资料取自Microsoft Document,并参考此内容以了解有关将 Key Vault 配置添加到应用程序的更多信息。

    【讨论】:

      猜你喜欢
      • 2023-01-12
      • 2015-07-24
      • 2017-04-16
      • 2019-07-25
      • 2020-02-05
      • 2017-08-03
      • 1970-01-01
      • 2023-02-01
      • 2016-08-18
      相关资源
      最近更新 更多