zoukankan      html  css  js  c++  java
  • 读取配置文件包含properties和xml文件

    读取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();
  • 相关阅读:
    计算机原理及硬件介绍
    python学习之由
    IDEA如何设置JVM参数
    Java函数式编程
    ubuntu更换源
    ubuntu 安装时没有设置root密码,如何登陆root
    ubuntu16.04镜像下载地址
    Elasticsearch Search APIs
    Elasticsearch Document APIs
    Elasticsearch搜索
  • 原文地址:https://www.cnblogs.com/atomicbomb/p/6755776.html
Copyright © 2011-2022 走看看