读取配置文件中的参数值

config.peoperties位于src/main/resource目录下

#oss信息
oss.endpoint=xxx
oss.accesskey_id=xxx
oss.accesskey_secret=xxx
import java.util.Properties;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;


public class OssUtil {

public static void main(String[] args) {
        Properties prop = PropertiesLoaderUtils.loadProperties(new ClassPathResource("/config.properties"));
        String value = prop.getProperty("oss.endpoint");
    }
}

猜你喜欢

转载自blog.csdn.net/atongmu2017/article/details/82746517