gpt4 book ai didi

java - 在应用程序运行时更新 Spring Boot 属性的更好方法

转载 作者:搜寻专家 更新时间:2023-11-01 00:54:33 25 4
gpt4 key购买 nike

到目前为止,我已经看到了更新 Spring Boot 应用程序的方法,通过更改属性文件本身,然后重新加载文件,或者通过使用 @RefreshScope 注释,或者通过 Spring Cloud Config。

我找不到任何直接的东西(比如 getEnvironment().updateProperty(key, value) )。

有这样的方法吗?

例如,我需要更改我的应用程序的日志记录类型,以显示 SQL;我的 application.properties 文件包含这一行:spring.jpa.show-sql=false

但是,如果我想在应用程序运行时通过 REST 调用将其设置为 true 怎么办?

您能推荐一种更简单的方法吗?和/或举例说明您将如何为这个特定的属性(property)做这件事?

编辑:更改不需要反射(reflect)在 application.properties 文件中。因此,当应用程序重新启动时,它将使用最初在 application.properties 文件中设置的属性。

最佳答案

部分回答推荐Spring Cloud Config Server。对某些人来说,这可能有点矫枉过正。这个 SO 答案正是您要找的。 How to hot reload properties in Spring Boot and Java EE

关于java - 在应用程序运行时更新 Spring Boot 属性的更好方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45940630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com