maven工程仿springboot手写代码区分开发测试生产
Posted carlo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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", ""));
以上是关于maven工程仿springboot手写代码区分开发测试生产的主要内容,如果未能解决你的问题,请参考以下文章
Java项目:仿小米商城系统(前后端分离+java+vue+Springboot+ssm+mysql+maven+redis)
SpringBoot项目的创建:手动创建一个Maven工程,然后引入SpringBoot所需的dependency来完成 (不需联网,但复杂)