@RefreshScope 配置文件自动刷新

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.配置文件

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

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

猜你喜欢

转载自blog.csdn.net/Anenan/article/details/85134208