maven工程仿springboot手写代码区分开发测试生产
2020-12-13 02:10
阅读:550
标签:package port imp maven工程 读取 elements als map Fix
读取代码:
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 ConcurrentMapapplicationMap = 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 getInstance() { return getInstance("application-"); } public static ConcurrentMap 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 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", "")); } }
maven工程仿springboot手写代码区分开发测试生产
标签:package port imp maven工程 读取 elements als map Fix
原文地址:https://www.cnblogs.com/carlo/p/11027530.html
文章来自:搜素材网的编程语言模块,转载请注明文章出处。
文章标题:maven工程仿springboot手写代码区分开发测试生产
文章链接:http://soscw.com/essay/25044.html
文章标题:maven工程仿springboot手写代码区分开发测试生产
文章链接:http://soscw.com/essay/25044.html
评论
亲,登录后才可以留言!