@Value("${test.test}")
private String nameValue;
@Autowired
private Student student;
//1.直接使用 @Value
new Thread(
() -> {
while (true) {
Date date = new Date();
log.info("当前时间:[{}],当前nameValue:[{}]", date, nameValue);
}
}, "test-thread").start();
//2.直接使用@ConfigurationProperties
@Data
@Component
@ConfigurationProperties(prefix = "test")
public class Student {
private String test;
}
new Thread(
() -> {
while (true) {
Date date = new Date();
log.info("当前时间:[{}],当前nameValue:[{}]", date, student.getTest());
}
}, "test-thread").start();
使用@Value不能自动刷新,而使用@ConfigurationProperties注入到容器可以做到自动刷新