springbootstatic代码读取application.properties配置⽂件属
公司起名大全2020最新版的性
PropertiesLoader:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.DefaultResourceLoader;
import io.Resource;
import io.ResourceLoader;
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
利姆露
import java.util.Properties;
public class PropertiesLoader {
private static Logger logger = Logger(PropertiesLoader.class);
private static ResourceLoader resourceLoader = new DefaultResourceLoader();
private final Properties properties;
public resourcesPaths) {
this.properties = this.loadProperties(resourcesPaths);
}
public Properties getProperties() {
return this.properties;
}
private String getValue(String key) {
String systemProperty = Property(key);
if (systemProperty != null) {
return systemProperty;
} else {
return ainsKey(key) ? Property(key) : "";
}
}
sd内存卡无法格式化
public String getProperty(String key) {
String value = Value(key);
if (value == null) {
throw new NoSuchElementException();
} else {
return value;
}
}
public String getProperty(String key, String defaultValue) {
String value = Value(key);
return value != null ? value : defaultValue;
}
public Integer getInteger(String key) {
String value = Value(key);
if (value == null) {
throw new NoSuchElementException();
} else {
return Integer.valueOf(value);
}
}
public Integer getInteger(String key, Integer defaultValue) {
String value = Value(key);
return value != null ? Integer.valueOf(value) : defaultValue;
}
public Double getDouble(String key) {
String value = Value(key);
if (value == null) {
throw new NoSuchElementException();
} else {
return Double.valueOf(value);
}
}
public Double getDouble(String key, Integer defaultValue) {
String value = Value(key);
return value != null ? Double.valueOf(value) : (double) defaultValue;
}
public Boolean getBoolean(String key) {
String value = Value(key);
if (value == null) {
throw new NoSuchElementException();
} else {
return Boolean.valueOf(value);
}
cf烟雾头怎么调}
public Boolean getBoolean(String key, boolean defaultValue) {
String value = Value(key);
梦见老婆怀孕了return value != null ? Boolean.valueOf(value) : defaultValue;
}
private Properties resourcesPaths) {
Properties props = new Properties();
String[] var3 = resourcesPaths;
int var4 = resourcesPaths.length;
for (int var5 = 0; var5 < var4; ++var5) {
String location = var3[var5];
InputStream is = null;
try {
Resource resource = Resource(location);
is = InputStream();
props.load(is);
} catch (IOException var12) {
logger.info("Could not load properties from path:" + location + ", " + Message());            } finally {
try {
if (is != null) {
is.close();
}
} catch (Exception e) {
e.printStackTrace();
}读取配置文件失败
}
}
return props;
}
}
PropertiesUtil:
llect.Maps;
import java.util.Map;
public class PropertiesUtil {
private static Map<String, String> map = wHashMap();
private static PropertiesLoader loader = new PropertiesLoader(new String[]{"application.properties"});
public static String getConfig(String key) {
String value = (key);
if (value == null) {
value = Property(key);
map.put(key, value != null ? value : "");
}
return value;
}
}
配置⽂件:
静态代码块读取配置⽂件:
static {
try {
String participates = Config("participates");
} catch (Exception e) {
<("加载配置出错:{}", e.getMessage());
}
}