package com.tzld.piaoquan.api.util; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import java.io.IOException; import java.io.InputStream; import java.util.Properties; @Slf4j public class BasePropertiesUtils { public static Properties properties; static { Properties mainProperties = new Properties(); properties = new Properties(); try { InputStream mainStream = BasePropertiesUtils.class.getClassLoader().getResourceAsStream("application.properties"); mainProperties.load(mainStream); // 先通过虚拟机参数 -Denv=value去取配置文件的值 // 如果没有设置-Denv的虚拟机参数则说明是本地开发环境,则读取application.properties文件中spring.profiles.active的值 String env = System.getProperty("env"); if (StringUtils.isEmpty(env)) { env = mainProperties.getProperty("spring.profiles.active"); } if (StringUtils.isEmpty(env)) { log.error("设置spring.profiles.active or 设置虚拟机启动参数 -Denv错误!!!"); System.exit(1); } InputStream activeStream = BasePropertiesUtils.class.getClassLoader().getResourceAsStream("application.properties"); properties.load(activeStream); log.info("开发环境为: " + env); } catch (IOException e) { log.error(e.getMessage()); System.exit(1); } } public static Properties getProperties() { return properties; } public static String getVideoBucket() { return getProperties().getProperty("oss.video.bucket"); } public static String getLongvideoStsEndpoint() { return getProperties().getProperty("oss.longvideo.video.sts.endpoint"); } public static String getLongvideoStsAccessKeyId() { return getProperties().getProperty("oss.longvideo.video.sts.accessKeyId"); } public static String getLongvideoStsAccessKeySecret() { return getProperties().getProperty("oss.longvideo.video.sts.accessKeySecret"); } public static String getLongvideoStsRoleArn() { return getProperties().getProperty("oss.longvideo.video.sts.roleArn"); } public static String getLongvideoStsSessionName() { return getProperties().getProperty("oss.longvideo.video.sts.roleSessionName"); } public static String getOssaccelerateUploadDomain() { return getProperties().getProperty("ossaccelerate.upload.domain"); } }