zoukankan      html  css  js  c++  java
  • maven工程仿springboot手写代码区分开发测试生产

    读取代码:

    package com.jz.compute.mc.v2.config;
    
    import java.util.Enumeration;
    import java.util.ResourceBundle;
    import java.util.concurrent.ConcurrentHashMap;
    import java.util.concurrent.ConcurrentMap;
    
    public class PropertiesConfig {
    
        public static volatile ConcurrentMap<String, String> applicationMap = new ConcurrentHashMap<>();
        private final static String dev = "dev";
        private final static String test = "test";
        private final static String prod = "prod";
    
        private PropertiesConfig() {
        }
    
        public static ConcurrentMap<String, String> getInstance() {
            return getInstance("application-");
    
        }
    
        public static ConcurrentMap<String, String> getInstance(String filePrefix) {
            if (applicationMap.size() == 0) {
                synchronized (PropertiesConfig.class) {
                    if (applicationMap.size() == 0) {
                        ResourceBundle application = ResourceBundle.getBundle("application");
                        ResourceBundle applicationActive = null;
                        String profilesActive = application.containsKey("profiles.active")
                                ? application.getString("profiles.active") : "";
                        if (PropertiesConfig.prod.equals(profilesActive)) {
                            applicationActive = ResourceBundle.getBundle(filePrefix + "prod");
                        } else if (PropertiesConfig.test.equals(profilesActive)) {
                            applicationActive = ResourceBundle.getBundle(filePrefix + "test");
                        } else if (PropertiesConfig.dev.equals(profilesActive)) {
                            applicationActive = ResourceBundle.getBundle(filePrefix + "dev");
                        } else {
                        }
    
                        Enumeration<String> keys = application.getKeys();
                        while (keys.hasMoreElements()) {
                            String key = keys.nextElement();
                            applicationMap.put(key, application.getString(key));
                        }
                        if (null != applicationActive) {
                            keys = applicationActive.getKeys();
                            while (keys.hasMoreElements()) {
                                String key = keys.nextElement();
                                applicationMap.put(key, applicationActive.getString(key));
                            }
                        }
                    }
                }
            }
            return applicationMap;
        }
    
        public static void main(String[] args) {
            System.out.println(PropertiesConfig.getInstance().getOrDefault("eicost.url", ""));
        }
    
    }
  • 相关阅读:
    Mac 系统环境变量配置
    sublime3+quick3.5 完整使用教程
    httprunner 2.5.7 下.env 文件环境变量的使用及debugtalk的使用,对test的参数化及执行
    python_request的安装及模拟json的post请求及带参数的get请求
    windows 下安装Charles,破解,安装证书,设置可抓取https包
    jmeter元件的执行顺序
    jmeter的参数化实现
    jmeter工作目录介绍、jmeter元件及组件介绍
    jmeter设置成中文显示
    win10下安装jmeter
  • 原文地址:https://www.cnblogs.com/carlo/p/11027530.html
Copyright © 2011-2022 走看看