如何在应用程序启动后在运行时加载Spring Boot中的属性而不需要重新启动

问题描述 投票:0回答:2

应用程序属性

spring.age=10

启动 Spring Boot 应用程序后,我想更改属性。

应用程序属性

spring.age=20

age=20应该加载而不需要重新启动spring boot。

我尝试使用@ConditionOnProperty,但即使这样也必须重新启动才能反映我是否错了。

java spring spring-boot properties microservices
2个回答
0
投票

此处提到的任何方法有帮助吗? 有提到

使用Spring Cloud的刷新能力
  1. 培养内部能力
  2. 这两种方法看起来确实有点过头了,但还是取决于你的场景。

我至少在

springboot docos

中找不到任何此类现有功能


0
投票

@Value("${spring.age}") String springAge;

创建 Spring bean 时使用该值。
即使您更改属性也不会产生任何影响。
您应该考虑使用属性的另一种方式。
例如,您可以每分钟读取 application.properties
如果属性发生更改,请手动设置相应的值。

© www.soinside.com 2019 - 2024. All rights reserved.