【问题标题】:Auto reloading properties file after updating it in Spring. How to achieve this?在 Spring 中更新后自动重新加载属性文件。如何做到这一点?
【发布时间】:2019-09-12 10:03:17
【问题描述】:

我希望我的属性文件自动刷新,而不是每次我进行任何更改时都重新启动服务器。我在 src/main/resources 中的属性文件

【问题讨论】:

  • 自动构建?你试过吗?

标签: spring properties-file


【解决方案1】:

您可以使用执行器,基本上您将配置 bean 放在刷新范围内:

@SpringBootApplication
public class ExampleServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(ExampleServiceApplication.class, args);
    }

    @RestController
    @RefreshScope
    class ExampleController {

        @Value("${foo.bar}")
        private String value;

        @RequestMapping
        public String sayValue() {
            return value;
        }
    }
}

然后当你改变配置。您调用执行器的刷新端点。

curl -X POST http://localhost:8080/refresh  

【讨论】:

    猜你喜欢
    • 2012-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-26
    • 2017-01-16
    • 2016-06-12
    • 1970-01-01
    相关资源
    最近更新 更多