package com.ctrip.framework.apollo.demo.spring.springBootDemo.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author Jason Song(song_s@ctrip.com)
 */
@ConfigurationProperties(prefix = "redis.cache")
@Component("sampleRedisConfig")
@RefreshScope
public class SampleRedisConfig {
  private static final Logger logger = LoggerFactory.getLogger(SampleRedisConfig.class);

  private int expireSeconds;
  private String clusterNodes;
  private int commandTimeout;

  @PostConstruct
  private void initialize() {
    logger.info("SampleRedisConfig initialized - expireSeconds: {}, clusterNodes: {}, commandTimeout: {}",
        expireSeconds, clusterNodes, commandTimeout);
  }

  public void setExpireSeconds(int expireSeconds) {
    this.expireSeconds = expireSeconds;
  }

  public void setClusterNodes(String clusterNodes) {
    this.clusterNodes = clusterNodes;
  }

  public void setCommandTimeout(int commandTimeout) {
    this.commandTimeout = commandTimeout;
  }

  @Override
  public String toString() {
    return String.format("[SampleRedisConfig] expireSeconds: %d, clusterNodes: %s, commandTimeout: %d",
        expireSeconds, clusterNodes, commandTimeout);
  }
}

@@ -64,16 +64,140 @@
 onfig;%0A%0A
+import com.google.common.collect.Lists;%0Aimport com.google.common.collect.Maps;%0Aimport java.util.List;%0Aimport java.util.Map;%0A
 import o
@@ -488,16 +488,321 @@
 t;%0A%0A/**%0A
+ * You may set up data like the following in Apollo:%0A * %3Cpre%3E%0A * redis.cache.expireSeconds = 100%0A * redis.cache.clusterNodes = 1,2%0A * redis.cache.commandTimeout = 50%0A * redis.cache.someMap.key1 = a%0A * redis.cache.someMap.key2 = b%0A * redis.cache.someList%5B0%5D = c%0A * redis.cache.someList%5B1%5D = d%0A * %3C/pre%3E%0A *%0A
  * @auth
@@ -965,16 +965,17 @@
 onfig %7B%0A
+%0A
   privat
@@ -1147,16 +1147,139 @@
 meout;%0A%0A
+  private Map%3CString, String%3E someMap = Maps.newLinkedHashMap();%0A  private List%3CString%3E someList = Lists.newLinkedList();%0A%0A
   @PostC
@@ -1333,16 +1333,25 @@
 er.info(
+%0A        
 %22SampleR
@@ -1427,16 +1427,43 @@
 Timeout:
+ %7B%7D, someMap: %7B%7D, someList:
  %7B%7D%22,%0A  
@@ -1507,24 +1507,43 @@
 mmandTimeout
+, someMap, someList
 );%0A  %7D%0A%0A  pu
@@ -1832,16 +1832,149 @@
 t;%0A  %7D%0A%0A
+  public Map%3CString, String%3E getSomeMap() %7B%0A    return someMap;%0A  %7D%0A%0A  public List%3CString%3E getSomeList() %7B%0A    return someList;%0A  %7D%0A%0A
   @Overr
@@ -2031,16 +2031,25 @@
 .format(
+%0A        
 %22%5BSample
@@ -2116,19 +2116,50 @@
 eout: %25d
-%22,%0A
+, someMap: %25s, someList: %25s%22,%0A    
         
@@ -2201,16 +2201,35 @@
 dTimeout
+, someMap, someList
 );%0A  %7D%0A%7D

add more ConfigurationProperties sample