1.在类上加@RefreshScope注解。

2.引入配置@Value。

/**
 * @author 向振华
 * @date 2018/12/17 17:20
 */
@RefreshScope //配置文件自动刷新
@RestController
@RequestMapping("test")
public class TestController {
 
    @Value("${test.xzh}") //引入配置
    private String xzh;
 
    @RequestMapping("/test1")
    public String test1(){
        return xzh;
    }
 
}

3.配置文件

#配置
test.xzh=xiangzhenhua
 
#动态刷新配置 ---需要忽略权限拦截
management.security.enabled=false

4.git配置webhooks,也可手动发送POST请求 http://localhost:1003/refresh

@RefreshScope 自动刷新配置文件的实例讲解

PS:在Spring Boot升级到2.0.3.RELEASE后需新增配置

management.endpoints.web.exposure.include=refresh

此时刷新配置文件url为:http://localhost:1003/actuator/refresh

原文地址:https://blog.csdn.net/Anenan/article/details/85134208

相关文章:

  • 2022-02-09
  • 2022-12-23
  • 2021-10-11
  • 2021-12-07
  • 2022-12-23
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-06
  • 2022-12-23
  • 2021-12-22
  • 2022-12-23
  • 2021-10-20
  • 2022-01-30
相关资源
相似解决方案