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();
  • 相关阅读:
    javascript模板方法模式
    设计模式之原型模式
    es6 工厂模式
    js建筑者模式
    程序运行时的堆栈与数据结构中的堆栈有何分别
    POJO、JavaBean、DTO的区别
    AnnotationTransactionAttributeSource is only available on Java 1.5 and higher
    进程pid理解
    Tasklist使用详解
    day 16 类的成员
  • 原文地址:https://www.cnblogs.com/atomicbomb/p/6755776.html
Copyright © 2011-2022 走看看