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

Pandora ·
更新时间:2024-09-20
· 1916 次阅读

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

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

management.endpoints.web.exposure.include=refresh

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

到此这篇关于@RefreshScope 自动刷新配置文件的文章就介绍到这了,更多相关@RefreshScope 配置文件自动刷新内容请搜索软件开发网以前的文章或继续浏览下面的相关文章希望大家以后多多支持软件开发网!



配置文件

需要 登录 后方可回复, 如果你还没有账号请 注册新账号
相关文章