spring学习第一天

spring中ClassPathXmlApplicationContext类是如何解析的?
https://www.cnblogs.com/dream-saddle/p/9449870.html
/*
this.placeholderPrefix: ${
this.placeholderSuffix: }
this.valueSeparator: :
*/
protected String parseStringValue(
String strVal, PlaceholderResolver placeholderResolver, Set visitedPlaceholders) {

StringBuilder result = new StringBuilder(strVal);

//获取 KaTeX parse error: Expected '}', got 'EOF' at end of input: …符串的最后一个字符串索引 如:{config}.xml,就是 KaTeX parse error: Expected 'EOF', got '}' at position 51: …际逻辑并不是这样,而是获取 "}̲" 的位置,具体还请读者跟进方…{} 中的部分
String placeholder = result.substring(startIndex + this.placeholderPrefix.length(), endIndex);
String originalPlaceholder = placeholder;
if (!visitedPlaceholders.add(originalPlaceholder)) {
throw new …;
}
// Recursive invocation, parsing placeholders contained in the placeholder key.
       //递归调用了一次
placeholder = parseStringValue(placeholder, placeholderResolver, visitedPlaceholders);
// Now obtain the value for the fully resolved key…
       //根据占位符从 systemProperties,systemEnvironment 中获取值,获取的就是 System.setProperty(key, value) 中的 value
String propVal = placeholderResolver.resolvePlaceholder(placeholder);
if (propVal == null && this.valueSeparator != null) {
int separatorIndex = placeholder.indexOf(this.valueSeparator);
if (separatorIndex != -1) {
String actualPlaceholder = placeholder.substring(0, separatorIndex);
String defaultValue = placeholder.substring(separatorIndex + this.valueSeparator.length());
propVal = placeholderResolver.resolvePlaceholder(actualPlaceholder);
if (propVal == null) {
propVal = defaultValue;
}
}
}
if (propVal != null) {
// Recursive invocation, parsing placeholders contained in the
// previously resolved placeholder value.
propVal = parseStringValue(propVal, placeholderResolver, visitedPlaceholders);
         //将获取到的值进行替换,得到的就是配置文件真实名称
result.replace(startIndex, endIndex + this.placeholderSuffix.length(), propVal);
if (logger.isTraceEnabled()) {
…;
}
startIndex = result.indexOf(this.placeholderPrefix, startIndex + propVal.length());
}
else if (this.ignoreUnresolvablePlaceholders) {
// Proceed with unprocessed value.
startIndex = result.indexOf(this.placeholderPrefix, endIndex + this.placeholderSuffix.length());
}
else {
throw new …;
}
visitedPlaceholders.remove(originalPlaceholder);
}
else {
startIndex = -1;
}
}

return result.toString();

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值