Skip to content

Apollo——使用技巧

教程文件: https://www.apolloconfig.com/#/zh/README

JSON的话可以注入一下String类型,获取key-value字段后程序再做反序列化操作;

依赖注入写法可以写一个公共配置属性类,然后注入这个类就行,同时加一个自动刷新的配置+配置类Bean注入的方式。

@Data  
@ConfigurationProperties(prefix = "mrs")  
public class MrsActivityConfigProperties {  
  
    @Data  
    @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)  
    public static class MrsIsKeepAudit {  
        Long organizerConfigId;  
        Long typeConfigId;  
    }  
  
  
    /**  
     * 活动库存填写下限  
     */  
    private Integer reportInventoryLowerLimit = 3;  
  
    //改为支持多个配置,改为获取JSON数据  
    private String mrsIsKeepAudit;  
  
  
    public List<MrsIsKeepAudit> getMrsIsKeepAuditList() {  
        return JsonTools.defaultMapper().fromJson(mrsIsKeepAudit, new TypeReference<List<MrsIsKeepAudit>>() {});  
    }  
}