@Component
@ConfigurationProperties("person")
@RefreshScope
@Validated
public class PersonConfiguration {
@NotBlank
public String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@RestController
class MessageRestController {
@EventListener(RefreshScopeRefreshedEvent.class)
void onRefresh(RefreshScopeRefreshedEvent event) {
System.out.println("entering refresh");
System.out.println("exiting refresh");
}
}
person:
name: aaaa
每当名称更改时,都会在MessageRestController中调用onRefresh方法。当名称更改为空字符串时,有一种方法可以限制onRefresh方法的调用,因为它不是PersonConfiguration类中的有效字符串。