java - 您可以在 application.properties 中引用 Azure Key Vault secret 吗?

标签 java spring-boot azure azure-keyvault

我有一条记录:

@ConfigurationProperties("service.api")
@ConstructorBinding
public record ServiceApiConfig(String clientId, String clientSecret) {}

和一个application.properties文件:

service.api.client_id=client_id
service.api.client_secret=client_secret

当我进行本地开发时,绑定(bind)有效。

我想要做的是使用 Azure 服务(Azure Spring Apps、Key Vault 等),我的问题是我是否可以在 application.properties 文件内引用存储在 Key Vault 中的 secret 。像这样的事情:

service.api.client_id=<name-of-the-id-kept-in-the-vault>
service.api.client_secret=<name-of-the-secret-kept-in-the-vault>

我见过的教程让我认为进行绑定(bind)的唯一方法是在 java 类中的字段上使用 @Value("${nameOfTheSecret}") 注释。可以按照我想要的方式来做吗?

最佳答案

您可以通过添加要从 Spring Boot 应用程序连接的 Azure Key Vault 的以下属性来引用 application.properties 文件中的 Azure Key Vault secret :

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>

关于java - 您可以在 application.properties 中引用 Azure Key Vault secret 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73637387/

相关文章:

java - 考虑在您的配置中定义一个类型为 'org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository' 的 bean

azure - 从 Azure CI 访问私有(private) bitbucket 存储库

java - FOR EACH 循环中的并行迭代

java - 将 RestTemplate 与 SSL 一起使用

docker - docker容器上传文件

azure - RabbitMQ 对比适用于 Microsoft Azure 云平台的 MSMQ

azure - 在 Azure CosmosDB 中 - 对用户禁用数据资源管理器

java - 由 : org. usb4java.LoaderException : Native library not found in classpath:/org/usb4java/windows-x86/libusb-1. 0.dll 引起

java - java中sigar如何计算机器位模式

java 8 如何获得多个属性的不同列表