package com.elab.spring.componts.config;

import com.elab.spring.utils.SpringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 配置刷新获取
 *
 * @author liukaixiong
 * @Email liukx@elab-plus.com
 */
public class ConfigRefreshHelper implements ConfigRefresh {

    private Logger logger = LoggerFactory.getLogger(getClass());

    private static ConfigRefreshHelper INSTANCE = new ConfigRefreshHelper();

    public static ConfigRefreshHelper getInstance() {
        return INSTANCE;
    }

    @Override
    public String get(String key) {
        try {
            ConfigRefresh configRefresh = SpringUtils.getBean(ConfigRefresh.class);
            return configRefresh.get(key);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
        return null;
    }

    @Override
    public <T> T get(String key, Class<T> clazz) {
        try {
            ConfigRefresh configRefresh = SpringUtils.getBean(ConfigRefresh.class);
            return configRefresh.get(key, clazz);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
        return null;
    }
}
