springboot使用外部tomcat获取自定义配置文件

public class UnitConfig {
	//private static ResourceBundle resourceBundle;
	private static Properties pro;
	
    static{
    	//resourceBundle= ResourceBundle.getBundle("offine_config");
    	pro = new Properties();
        InputStreamReader in=null;
            try {
                in=new InputStreamReader(UnitConfig.class.getResourceAsStream("/unitConfig.properties"),"utf-8");
                pro.load(in);
            } catch (FileNotFoundException e) {
                System.out.println("找不到配置文件");
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }finally {
                if(in!=null){
                    try {
                        in.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
    }
    
    public static String getValue(String key) {//传入键
    	return pro.getProperty(key);
    }
 }

 

你可能感兴趣的:(Java)