1、bootstrap.yml中的配置属性 无法动态刷新
只能添加在application.yml中
2、需要在调用的地方添加@RefreshScope、不能只在Application上添加
3 、需要引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
4、在线程中引用无效、在线程while循环 该变量的值一直不变
@Value("${coffee.prop.name}")
private String name;
@Override
public void afterPropertiesSet() throws Exception {
new Thread(new Runnable() {
@Override
public void run() {
while (true) {
try {
Thread.sleep(1000 * 2);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(name);
}
}
}).start();
}
正确的用法
@RestController
@RefreshScope
public class RefreshController {
@Value("${coffee.prop.name}")
private String name;
@GetMapping("getName")
public String getName() {
return name;
}
}