zoukankan      html  css  js  c++  java
  • apollo 从配置中获取某个配置

    package com.sea.comon.utils;
    
    import java.text.MessageFormat;
    
    import org.springframework.beans.factory.InitializingBean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.util.StringUtils;
    
    import com.ctrip.framework.apollo.Config;
    import com.ctrip.framework.apollo.ConfigService;
    
    /**
     * apollo国际化配置文件
     * 
     * @author Merlin
     *
     */
    @Configuration
    public class ApolloMessageUtil implements InitializingBean {
    
        private static Config enPublicConfig = ConfigService.getConfig("message"); // apollo 总创建的命名空间名字
    
        private static ApolloMessageUtil apolloMessage = null;
    
        public static ApolloMessageUtil getApolloMessage() {
            return apolloMessage;
        }
    
        @Override
        public void afterPropertiesSet() throws Exception {
            apolloMessage = this;
        }
    
        public static String getString(String key, Object[] params) {
            String msg = null;
            if (!StringUtils.isEmpty(key)) {
    
                String messageKey = enPublicConfig.getProperty(key, "");
                msg = MessageFormat.format(messageKey, params);
            }
            return msg;
        }
        
        public static String getString(String key) {
            String msg = null;
            if (!StringUtils.isEmpty(key)) {
    
                msg = enPublicConfig.getProperty(key, "");
            }
            return msg;
        }
        
        public static String getString(Config config ,String key) {
            String msg = null;
            if (!StringUtils.isEmpty(key)) {
    
                msg = config.getProperty(key, "");
            }
            return msg;
        }
    }
  • 相关阅读:
    从零搭建hadoop集群之安装虚拟机
    数据库中的左连接和右连接的区别
    cookie 和session的区别是
    jquery获取单选按钮选中的值
    css设置背景图(背景图太大导致图片显示不全)
    vue购物车
    model修改器获取器的使用
    model时间戳自动添加
    定义路由
    模型使用:M模型 V视图 C控制
  • 原文地址:https://www.cnblogs.com/lshan/p/11791402.html
Copyright © 2011-2022 走看看