• 读取配置文件包含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();
  • 相关阅读:
    Linux基础知识
    c语言依赖倒转
    ios的认识
    ios数据的基本类型和流程控制
    JavaScript 创建 自定义对象
    《大道至简》读后感
    总结
    字符串转换成整型并求和
    《大道之简》第二章
    SQL Server 2008 数据库自动备份
  • 原文地址:https://www.cnblogs.com/atomicbomb/p/6755776.html
Copyright © 2020-2023  润新知