// Path: shiziqiu-configuration-core/src/main/java/com/shiziqiu/configuration/core/zk/ShiZiQiuConfClient.java
// public class ShiZiQiuConfClient {
// 
// 	private static Logger logger = LoggerFactory.getLogger(ShiZiQiuConfClient.class);
// 	public static Properties localProp = PropertiesUtil.loadProperties("local.properties");
// 	private static Cache cache;
// 	
// 	static {
// 		CacheManager manager = CacheManager.create();
// 		cache = new Cache(Configure.CONF_DATA_PATH, 10000, false, true, 1800, 1800);
// 		manager.addCache(cache);
// 	}
// 	
// 	public static void set(String key, String value) {
// 		if (cache != null) {
// 			logger.info(">>>>>>>>>> shiziqiu-conf: 初始化配置: [{}:{}]", new Object[]{key, value});
// 			cache.put(new Element(key, value));
// 		}
// 	}
// 	
// 	public static void update(String key, String value) {
// 		if (cache != null) {
// 			if (cache.get(key)!=null) {
// 				logger.info(">>>>>>>>>> shiziqiu-conf: 更新配置: [{}:{}]", new Object[]{key, value});
// 				cache.put(new Element(key, value));
// 			}
// 		}
// 	}
// 	
// 	public static String get(String key, String defaultVal) {
// 		if (localProp!=null && localProp.containsKey(key)) {
// 			return localProp.getProperty(key);
// 		}
// 		if (cache != null) {
// 			Element element = cache.get(key);
// 			if (element != null) {
// 				return (String) element.getObjectValue();
// 			}
// 		}
// 		String zkData = ShiZiQiuZkConfClient.getPathDataByKey(key);
// 		if (zkData!=null) {
// 			set(key, zkData);
// 			return zkData;
// 		}
// 
// 		return defaultVal;
// 	}
// 
// 	public static boolean remove(String key) {
// 		if (cache != null) {
// 			logger.info(">>>>>>>>>> shiziqiu-conf: 删除配置：key ", key);
// 			return cache.remove(key);
// 		}
// 		return false;
// 	}
// 
// 	public static void main(String[] args) {
// 		String key = "key";
// 		String value = "hello";
// 		set(key, value);
// 		System.out.println(get(key, "-1"));
// 	}
// 	
// 	
// }
// 
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/Constant.java
// public class Constant {
// 
// 	public static final String PLACEHOLDER_PREFIX = "${";
// 	public static final String PLACEHOLDER_SUFFIX = "}";
// 	public static final String LOGIN_PERM_KEY = "LOGIN_PERM";
// 	public static final String LOGIN_PERM_VAL = "1234567890";
// 
// 	// 默认缓存时间,单位/秒, 2H
// 	public static final int COOKIE_MAX_AGE = 60 * 60 * 2;
// 
// 	// 保存路径,根路径
// 	public static final String COOKIE_PATH = "/";
// }


import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionVisitor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.core.Ordered;
import org.springframework.util.StringValueResolver;
import com.shiziqiu.configuration.core.zk.ShiZiQiuConfClient;
import com.shiziqiu.configuration.util.Constant;
package com.shiziqiu.configuration.core.spring;



/**
 * @title : ShiZiQiuConfPlaceholderConfigurer
 * @author : crazy
 * @date : 2017年9月6日 下午5:11:04
 * @Fun :
 */
public class ShiZiQiuConfPlaceholderConfigurer extends PropertyPlaceholderConfigurer{

	private static Logger logger = LoggerFactory.getLogger(ShiZiQiuConfPlaceholderConfigurer.class);

	@Override
	protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException {
		StringValueResolver valueResolver = new StringValueResolver() {

			@Override
			public String resolveStringValue(String strVal) {
				StringBuffer sb = new StringBuffer(strVal);
				/**
				 * 给变量加上${XXXXXXX}
				 */
				boolean start = strVal.startsWith(Constant.PLACEHOLDER_PREFIX);
				boolean end = strVal.endsWith(Constant.PLACEHOLDER_SUFFIX);
				while(start && end) {
					String key = sb.substring(placeholderPrefix.length(), sb.length() - placeholderSuffix.length());
					String zkValue = ShiZiQiuConfClient.get(key, "");
					logger.info(">>>>>>>>>>> resolved placeholder '" + key + "' to value [" + zkValue + "]");
					sb = new StringBuffer(zkValue);
					start = sb.toString().startsWith(placeholderPrefix);
					end = sb.toString().endsWith(placeholderSuffix);
				}
				return sb.toString();
			}
		};
		BeanDefinitionVisitor visitor = new BeanDefinitionVisitor(valueResolver);
		String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames();
		if (null != beanNames && beanNames.length > 0) {
			for (String beanName : beanNames) {
// Path: shiziqiu-configuration-core/src/main/java/com/shiziqiu/configuration/core/zk/ShiZiQiuConfClient.java
// public class ShiZiQiuConfClient {
// 
// 	private static Logger logger = LoggerFactory.getLogger(ShiZiQiuConfClient.class);
// 	public static Properties localProp = PropertiesUtil.loadProperties("local.properties");
// 	private static Cache cache;
// 	
// 	static {
// 		CacheManager manager = CacheManager.create();
// 		cache = new Cache(Configure.CONF_DATA_PATH, 10000, false, true, 1800, 1800);
// 		manager.addCache(cache);
// 	}
// 	
// 	public static void set(String key, String value) {
// 		if (cache != null) {
// 			logger.info(">>>>>>>>>> shiziqiu-conf: 初始化配置: [{}:{}]", new Object[]{key, value});
// 			cache.put(new Element(key, value));
// 		}
// 	}
// 	
// 	public static void update(String key, String value) {
// 		if (cache != null) {
// 			if (cache.get(key)!=null) {
// 				logger.info(">>>>>>>>>> shiziqiu-conf: 更新配置: [{}:{}]", new Object[]{key, value});
// 				cache.put(new Element(key, value));
// 			}
// 		}
// 	}
// 	
// 	public static String get(String key, String defaultVal) {
// 		if (localProp!=null && localProp.containsKey(key)) {
// 			return localProp.getProperty(key);
// 		}
// 		if (cache != null) {
// 			Element element = cache.get(key);
// 			if (element != null) {
// 				return (String) element.getObjectValue();
// 			}
// 		}
// 		String zkData = ShiZiQiuZkConfClient.getPathDataByKey(key);
// 		if (zkData!=null) {
// 			set(key, zkData);
// 			return zkData;
// 		}
// 
// 		return defaultVal;
// 	}
// 
// 	public static boolean remove(String key) {
// 		if (cache != null) {
// 			logger.info(">>>>>>>>>> shiziqiu-conf: 删除配置：key ", key);
// 			return cache.remove(key);
// 		}
// 		return false;
// 	}
// 
// 	public static void main(String[] args) {
// 		String key = "key";
// 		String value = "hello";
// 		set(key, value);
// 		System.out.println(get(key, "-1"));
// 	}
// 	
// 	
// }
// 
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/Constant.java
// public class Constant {
// 
// 	public static final String PLACEHOLDER_PREFIX = "${";
// 	public static final String PLACEHOLDER_SUFFIX = "}";
// 	public static final String LOGIN_PERM_KEY = "LOGIN_PERM";
// 	public static final String LOGIN_PERM_VAL = "1234567890";
// 
// 	// 默认缓存时间,单位/秒, 2H
// 	public static final int COOKIE_MAX_AGE = 60 * 60 * 2;
// 
// 	// 保存路径,根路径
// 	public static final String COOKIE_PATH = "/";
// }


// Path: shiziqiu-configuration-core/src/main/java/com/shiziqiu/configuration/core/spring/ShiZiQiuConfPlaceholderConfigurer.java
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionVisitor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.core.Ordered;
import org.springframework.util.StringValueResolver;
import com.shiziqiu.configuration.core.zk.ShiZiQiuConfClient;
import com.shiziqiu.configuration.util.Constant;

package com.shiziqiu.configuration.core.spring;



/**
 * @title : ShiZiQiuConfPlaceholderConfigurer
 * @author : crazy
 * @date : 2017年9月6日 下午5:11:04
 * @Fun :
 */
public class ShiZiQiuConfPlaceholderConfigurer extends PropertyPlaceholderConfigurer{

	private static Logger logger = LoggerFactory.getLogger(ShiZiQiuConfPlaceholderConfigurer.class);

	@Override
	protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException {
		StringValueResolver valueResolver = new StringValueResolver() {

			@Override
			public String resolveStringValue(String strVal) {
				StringBuffer sb = new StringBuffer(strVal);
				/**
				 * 给变量加上${XXXXXXX}
				 */
				boolean start = strVal.startsWith(Constant.PLACEHOLDER_PREFIX);
				boolean end = strVal.endsWith(Constant.PLACEHOLDER_SUFFIX);
				while(start && end) {
					String key = sb.substring(placeholderPrefix.length(), sb.length() - placeholderSuffix.length());
					String zkValue = ShiZiQiuConfClient.get(key, "");
					logger.info(">>>>>>>>>>> resolved placeholder '" + key + "' to value [" + zkValue + "]");
					sb = new StringBuffer(zkValue);
					start = sb.toString().startsWith(placeholderPrefix);
					end = sb.toString().endsWith(placeholderSuffix);
				}
				return sb.toString();
			}
		};
		BeanDefinitionVisitor visitor = new BeanDefinitionVisitor(valueResolver);
		String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames();
		if (null != beanNames && beanNames.length > 0) {
			for (String beanName : beanNames) {
				if(!(beanName.equals(this.beanName)) && beanFactoryToProcess.equals(this.beanFactory)) {