【问题标题】:Programatically changing the application.properties file at runtime with Spring Boot使用 Spring Boot 在运行时以编程方式更改 application.properties 文件
【发布时间】:2020-07-16 22:33:52
【问题描述】:

是否可以在运行时覆盖 application.properties 文件,然后用 Spring Boot 重新加载?

我可以像更新其他文件一样简单地更新文件吗?如何告诉 Spring 重新加载新的配置值?

我不想在运行时简单地覆盖属性,我需要将更改保留回原始文件。

【问题讨论】:

    标签: java spring spring-boot


    【解决方案1】:

    /actuator/refresh 端点将完成这项工作。 您需要使用 @RefreshScope 注释来注释您的类(包含要重新加载的属性的类)。

    所以基本上修改您的 application.properties 文件,然后调用该端点并完成。

    请找到此link,了解有关执行器的更多信息。

    另一个link 有更多关于@RefreshScope 的详细信息。

    【讨论】:

    猜你喜欢
    • 2015-05-18
    • 2017-05-23
    • 2016-05-22
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 2016-11-17
    • 2019-02-19
    • 2015-05-23
    相关资源
    最近更新 更多