Apollo config配置中心 配置列表和map DEMO

2024-10-09 08:40:59 浏览数 (1)

Apollo config配置中心 配置列表和map DEMO #支持可扩展 Apollo配置 apollo中配置如下:

代码语言:javascript复制
defaultId = 100,200  
chooseId = {"300":"A","400":"B","500":"C"}
callback.url = http://localhost:8080/hello

java代码:

代码语言:javascript复制
@Configuration
@Data
public class TestConfig {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Value("#{'${defaultId:"100","200"}'.split(',')}")
    private List<String> defaultId;
    @Value("#{${chooseId:{"300":"A","400":"B","500":"C"}}}")
    private Map<String, String> chooseId;

    @Value("${callback.url:abc}")
    private String callbackUrl;

    
    @PostConstruct
    public void init(){
        logger.info("defaultId=[{}]", GsonUtils.toJson(defaultId));
        logger.info("chooseId=[{}]", GsonUtils.toJson(chooseId));
    }
}

0 人点赞