通常要把properties文件中的值给取出来
用springboot 的@value属性并不能很好的做到,只能在controller中赋给成员函数。
那么接下来自己做一个吧
。。。。。。
@Slf4j
public class PropertiesUtil {
private static Properties properties;
static {
String fileName="application.properties";
properties=new Properties();
try {
properties.load(new InputStreamReader(PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName)));
} catch (IOException e) {
log.error("配置文件读取异常",e);
}
}
public static String getPropertity(String key){
String value=properties.getProperty(key.trim());
if (StringUtils.isNotBlank(value)){
return value.trim();
}
return null;
}
public static String getPropertity(String key,String defaultValue){
String value=properties.getProperty(key.trim());
if (!StringUtils.isNotBlank(value)){
value=defaultValue;
}
return value.trim();
}
}