获取jar包配置文件踩坑记录

package com.saic.common.split.solve.utils;

import com.saic.common.split.solve.constant.CommonConstant;
import lombok.extern.slf4j.Slf4j;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

@Slf4j
public class PropertiesReadUtils {

public static String getPropertiesValue(String type, String splicingParam) {
try {
Properties properties = new Properties();
properties.load(acquireInputStream());
return properties.getProperty(type + splicingParam);
} catch (Exception e) {
log.error("getPropertiesValue...error", e);
}
return "";
}

private static InputStream acquireInputStream() {
try {
        //获取服务器指定位置下配置文件
return new BufferedInputStream(new FileInputStream(CommonConstant.PROPERTIES_URL));
} catch (Exception e) {
log.info("acquireInputStream error...application.properties fileNotFound in local");
}
      //获取项目打成jar包后的配置文件
return PropertiesReadUtils.class.getResourceAsStream("/application.properties");
}
}

posted @ 2022-03-17 14:03  currystar  阅读(101)  评论(0编辑  收藏  举报