简体   繁体   English

在运行时更新 Spring Boot 应用程序配置

[英]Updating spring boot application configuration at runtime

I have implemented shutdown API in my spring-boot project by setting following values in application.properties:我通过在 application.properties 中设置以下值在我的 spring-boot 项目中实现了关闭 API:

 management.endpoint.shutdown.enabled=true
 management.endpoint.info.enabled=true
 management.endpoints.web.exposure.include=*

Now I want to disable the shutdown API dynamically with help of database like I will have those above configurations as key, value pair that I can change anytime.现在我想在数据库的帮助下动态禁用关闭 API,就像我将上述配置作为键值对,我可以随时更改。

On its change, the application should get also updated with the new config values thereby shutdown API gets disabled .在更改时,应用程序也应该使用新的配置值更新,从而关闭 API 被禁用

You could use Netflix Archaius你可以使用Netflix Archaius

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-archaius</artifactId>
</dependency>

You don't need to use @Value annotation here.您不需要在此处使用@Value注释。

Usage用法

DynamicStringProperty dynamicProperty = DynamicPropertyFactory.getInstance().getStringProperty("management.endpoint.shutdown.enabled", "default value here");
String propertyCurrentValue = dynamicProperty.get();

If the data changes in property file at any point, Archaius will detect it at runtime and will start retrieving the new values.如果属性文件中的数据在任何时候发生变化,Archaius 将在运行时检测到它并开始检索新值。

Useful references有用的参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM