package com.xiaopeng.common.core.utils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.core.env.Environment;
|
import org.springframework.stereotype.Component;
|
|
@Component
|
public class ConfigUtils {
|
|
|
private static Environment env;
|
|
@Autowired
|
public void setEnv(Environment environment) {
|
ConfigUtils.env = environment;
|
}
|
|
public static String getProperty(String key) {
|
if (env == null) {
|
throw new IllegalStateException("Environment not injected yet");
|
}
|
return env.getProperty(key);
|
}
|
|
public static String getProperty(String key, String defaultValue) {
|
if (env == null) {
|
return defaultValue;
|
}
|
return env.getProperty(key, defaultValue);
|
}
|
|
}
|