Files
blog-backEnd/blog-common/src/main/java/cn/celess/common/util/EnvironmentUtil.java
禾几海 5a00e6c62f 记录项目配置,修改配置项的获取方式
- new class ` CommonEnvPostProcessor `
- remove ` @value `
- make JwtUtil's method static
2021-10-03 16:04:48 +08:00

48 lines
1.2 KiB
Java

package cn.celess.common.util;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import java.util.Map;
import java.util.Properties;
@Slf4j
public class EnvironmentUtil {
private static final Properties properties = new Properties();
public static String getEnv(String name) {
String value = System.getenv(name);
if (StringUtils.isBlank(value)) {
log.error("没有找到环境变量:" + name);
}
return value;
}
public static String getEnv(String name, String defaultValue) {
String env = getEnv(name);
if (env == null) {
return defaultValue;
}
return env;
}
public static String getProperties(String key) {
String value = properties.getProperty(key);
if (StringUtils.isBlank(value)) {
log.error("没有找到配置项: {}", key);
}
return value;
}
public static String getProperties(String key, String defaultValue) {
return properties.getProperty(key, defaultValue);
}
public static void addProperties(Map<?, ?> map) {
properties.putAll(map);
}
}