Springboot get the value XXX.properties file

package com.utils;

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

/**
 * 文件数值获取
 */
public class PropertyValues {

    public static Properties properties;
    static {
        loadPropertyValue();
    }
    public static void loadPropertyValue(){
        InputStream inputStream=null;
        inputStream= PropertyValues.class.getClassLoader().getResourceAsStream("wsData.properties");
        properties=new Properties();
        try {
            properties.load(inputStream);
        }catch (Exception e){
            System.out.println("get value failed!");
        }finally {
            try {
                inputStream.close();
            }catch (Exception e){
                System.out.println("IO close exception!");
            }

        }

    }

    public static String getPropertyValue(String key){
        if (properties==null){
            loadPropertyValue();
        }
        return  properties.getProperty(key);
    }
}

 

Guess you like

Origin blog.csdn.net/weixin_39102174/article/details/90616943