apollo配置动态更新

2020-02-13 13:49:22 浏览数 (1)

简单配置

使用@Value注解的配置会自动刷新配置

复杂对象

代码语言:javascript复制
@Component("systemConfig")
@ConfigurationProperties(prefix = "cword")
@RefreshScope
@EnableApolloConfig("cword")
public class SystemConfig {
 
    private Resource filePath;
    private Resource tempFilePath;
 
    @Autowired
    private org.springframework.cloud.context.scope.refresh.RefreshScope refreshScope;
    @ApolloConfigChangeListener("cword")
    private void configChange(ConfigChangeEvent changeEvent){
        refreshScope.refresh("systemConfig");
    }
}

0 人点赞