博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
读取配置文件包含properties和xml文件
阅读量:4476 次
发布时间:2019-06-08

本文共 1596 字,大约阅读时间需要 5 分钟。

读取properties配置文件

/** * 读取配置文件 * @author ll-t150 */public class Utils {        private static Properties props = new Properties();    private static InputStream inputStream = null;    private static String confPath = null;        static {        confPath = System.getProperty("conf");        try {            if(!StringUtils.isEmpty(confPath)){                inputStream = new FileInputStream(confPath.concat("/dinpay-sync.properties"));            }else{                ClassLoader cl = Utils.class.getClassLoader();                inputStream = cl.getResourceAsStream("dinpay-sync.properties");            }        } catch (FileNotFoundException e) {            e.printStackTrace();        }        try {            props.load(inputStream);        } catch (IOException e1) {            e1.printStackTrace();        }    }        public static String getString(String key){        String val = null;        val = props.getProperty(key);        return val;    }

 

读取spring的xml文件

private static AbstractApplicationContext appContext = null;    private static final String XML_EXPRESSION = "classpath*:applicationContext*.xml";    static {        // 后续来读取命令中的conf 例如 java -Dconf=conf/*.xml -classpath .:lib/*        if (System.getProperty("conf") != null) {            appContext = new FileSystemXmlApplicationContext(System.getProperty("conf").concat("/applicationContext-sync.xml"));        } else {            appContext = new ClassPathXmlApplicationContext(XML_EXPRESSION);        }    } appContext.registerShutdownHook(); appContext.start();

 

转载于:https://www.cnblogs.com/atomicbomb/p/6755776.html

你可能感兴趣的文章
Flask Web开发读书笔记
查看>>
"仿matlab科学软件"项目准备
查看>>
wordpress 插件推荐
查看>>
抽象工厂
查看>>
AC自动机
查看>>
防止重复提交的思路
查看>>
Linux tr命令使用方法
查看>>
jetty启动设置端口
查看>>
cyyz: Day 2 线段树知识整理
查看>>
[Selenium]计算坐标进行拖拽,重写dragAndDropOffset
查看>>
★《唐琅探案》后记【3】
查看>>
Angular学习笔记(2)
查看>>
双击启动tomcat中的startup.bat闪退原因及解决方法
查看>>
完成个人中心—导航标签
查看>>
【C++】C++中变量的声明与定义的区别
查看>>
前端性能优化
查看>>
static
查看>>
属性动画
查看>>
Swift 字符串
查看>>
Python 生成器 Generator 和迭代器 Iterator
查看>>