博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
maven工程仿springboot手写代码区分开发测试生产
阅读量:5113 次
发布时间:2019-06-13

本文共 2609 字,大约阅读时间需要 8 分钟。

读取代码:

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
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
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", "")); }}

 

转载于:https://www.cnblogs.com/carlo/p/11027530.html

你可能感兴趣的文章
P4学习:统计功能
查看>>
获取INET4与INET6的信息
查看>>
POJ 2316
查看>>
web.xml详解
查看>>
数据库里面的表数据导出到excel
查看>>
haar特征(转)
查看>>
WPF TextBox按字节长度限制输入
查看>>
IOS UITableView 加载图片 卡的问题
查看>>
LeetCode03 - 无重复字符的最长子串(Java 实现)
查看>>
ssh连接的时候出现 WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @解决方法
查看>>
Mysql存储写入速度慢分析
查看>>
利用Idea打包jar包
查看>>
MySQL 数据库 的安装和基本管理
查看>>
MyEclipse中JavaMail冲突问题
查看>>
四边形面积探索
查看>>
NYOJ 283
查看>>
Bootstrap总结二
查看>>
打死发送到发送到发送到发送到发斯蒂芬
查看>>
听风(2)
查看>>
受约束的10人参赛问题
查看>>