记录项目配置,修改配置项的获取方式
- new class ` CommonEnvPostProcessor ` - remove ` @value ` - make JwtUtil's method static
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user