美文网首页
2021-12-15 ContextLoader.proper

2021-12-15 ContextLoader.proper

作者: 归去来ming | 来源:发表于2021-12-15 23:18 被阅读0次

ContextLoader类中的静态代码块:

    static {
        // Load default strategy implementations from properties file.
        // This is currently strictly internal and not meant to be customized
        // by application developers.
        try {
            ClassPathResource resource = new ClassPathResource(DEFAULT_STRATEGIES_PATH, ContextLoader.class);
            defaultStrategies = PropertiesLoaderUtils.loadProperties(resource);
        }
        catch (IOException ex) {
            throw new IllegalStateException("Could not load 'ContextLoader.properties': " + ex.getMessage());
        }
    }

DEFAULT_STRATEGIES_PATH即是ContextLoader类的同目录下的属性文件ContextLoader.properties,内容为:

org.springframework.web.context.WebApplicationContext=org.springframework.web.context.support.XmlWebApplicationContext

跟踪PropertiesLoaderUtils.loadProperties(resource)方法,最终来到Properties类:

// Properties.java
private void load0 (LineReader lr) throws IOException {
        char[] convtBuf = new char[1024];
        int limit;
        int keyLen;
        int valueStart;
        char c;
        boolean hasSep;
        boolean precedingBackslash;

        while ((limit = lr.readLine()) >= 0) {
            c = 0;
            keyLen = 0;
            valueStart = limit;
            hasSep = false;

            //System.out.println("line=<" + new String(lineBuf, 0, limit) + ">");
            precedingBackslash = false;
            while (keyLen < limit) {
                c = lr.lineBuf[keyLen];
                //need check if escaped.
                // 当出现=或:时,就是key和value的分界点,跳出循环
                if ((c == '=' ||  c == ':') && !precedingBackslash) {
                    valueStart = keyLen + 1;
                    hasSep = true;
                    break;
                } else if ((c == ' ' || c == '\t' ||  c == '\f') && !precedingBackslash) {
                    valueStart = keyLen + 1;
                    break;
                }
                if (c == '\\') {
                    precedingBackslash = !precedingBackslash;
                } else {
                    precedingBackslash = false;
                }
                keyLen++;
            }
            while (valueStart < limit) {
                c = lr.lineBuf[valueStart];
                if (c != ' ' && c != '\t' &&  c != '\f') {
                    if (!hasSep && (c == '=' ||  c == ':')) {
                        hasSep = true;
                    } else {
                        break;
                    }
                }
                valueStart++;
            }
            String key = loadConvert(lr.lineBuf, 0, keyLen, convtBuf);
            String value = loadConvert(lr.lineBuf, valueStart, limit - valueStart, convtBuf);
            put(key, value);
        }
    }

相关文章

  • 2021-12-15 ContextLoader.proper

    ContextLoader类中的静态代码块: DEFAULT_STRATEGIES_PATH即是ContextLo...

  • Swift自定义log打印

    输出显示:"2021-12-15 14:29:38 [DefaultPageControlViewControll...

  • 周二竞足:拜仁一如既往凶猛,斯图加特或将大败

    周二001德甲:斯图加特VS拜仁慕尼黑 比赛时间:2021-12-15 01:30 SP(+2):2.15/4.2...

  • 《句句成章》29 霸不霸道

    原创 老区游子 游子岁月 2021-12-15 05:48 收录于话题 #佛山 4个内容 句子:存心他人开不过去,...

  • 《金吾生〈庄子发微〉日课13.2021-12-15》

    《金吾生〈庄子发微〉日课13.2021-12-15》 今天是辛丑庚子丁酉,冬月十二,2021-12-15星期三。 ...

  • 用功久,自有勇

    2021-12-15 成长学习课堂【用功久,自有勇】 《传习录》中,陈九川问阳明先生:“我自己反省起心动念就...

  • 2021-12-15

    2021-12-15 每日复盘 早餐:白米粥、肉松、鸡蛋 午餐:白米饭、海带排骨汤、清炒上海青 晚餐:紫菜煮面 水...

  • 2021-12-16晨间日志

    2021-12-15,星期三。 任城天气,多云,14~0度,中度雾霾,污染指数186,北风微风。 万宁天气多云,2...

  • 2021-12-15

    郭芳艳坚持原创分享第1313天 2021-12-15 生活感悟 前些日子,其实包括现在也还是会有一种觉察,当发现别...

  • 2021-12-15

    2021-12-15 星期三 天气:晴 温度:冷 相对而言,今年的十二月份气温要比往年温和许多的,对于这个冬天...

网友评论

      本文标题:2021-12-15 ContextLoader.proper

      本文链接:https://www.haomeiwen.com/subject/varmfrtx.html