Spring Boot azure keyvault 按需刷新

发布于 2025-01-14 20:52:06 字数 398 浏览 0 评论 0原文

我将 spring boot 与 azure 的 keyvault 一起使用,

    <dependency>
        <groupId>com.azure.spring</groupId>
        <artifactId>azure-spring-boot-starter-keyvault-secrets</artifactId>
    </dependency>

但是当我想更新密钥时出现问题。 例如,如何通过rest api强制刷新该值?

@Value("${x-value}") private val xValue: String = "0"

谢谢!

I am using spring boot with azure's keyvault

    <dependency>
        <groupId>com.azure.spring</groupId>
        <artifactId>azure-spring-boot-starter-keyvault-secrets</artifactId>
    </dependency>

but there is a problem, when I want to update secret.
How to force for example via rest api lets say, refresh of this value ?

@Value("${x-value}") private val xValue: String = "0"

thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烂人 2025-01-21 20:52:06

您能否重新表述您的问题以澄清您到底想要刷新什么?如果您想刷新 AKV 中的值(AKV 秘密更改 -> 代码更改中的值),您需要使用环境来获取属性:

@Autowired
Environment environment
...
xValue = environment.getProperty("x-value");

因为 @Value() 是在组件构建期间设置的。它在其一生中不会改变。

如果您想要更改 AKV 内容:这不是 azure-spring-boot-starter-keyvault-secrets 的目的。

Can you rephrase you're question to clarify what exactly do you want to refresh? If you want to refresh the value from AKV (AKV secret changes -> value in code changes) you need to use environment to get the property:

@Autowired
Environment environment
...
xValue = environment.getProperty("x-value");

because @Value() is set during construction of the component. It won't change during it's lifetime.

If you want the change the AKV contents: this is not the purpose of azure-spring-boot-starter-keyvault-secrets.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文