0
点赞
收藏
分享

微信扫一扫

nacos自动刷新配置


在使用​​Nacos​​作为配置中心时,我们希望能够在更改配置文件之后,可以同步到各个服务中,下面我们介绍一下2种实现方式。

配置文件:

test:
name: "test"

方式一:如果使用@ConfigurationProperties+@Configuration,不需要加@RefreshScope,也可以实现配置自动刷新

@Configuration
@ConfigurationProperties(prefix = "test")
public class CustomProperties {
private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}

方式二:如果使用@Value,需要加@RefreshScope,才能实现配置自动刷新

@RefreshScope
@Component
public class CustomProperties {

@Value("${test.name}")
private String name;

}

举报

相关推荐

0 条评论