spring 源码 窥视一
这段时间准备读下spring的源码。看 别人写的代码,确实是一件难事。第一,你不清楚需求,不知道他为什么要这么写。第二,继承啊,抽象啊一层层的,可以把你搞崩溃掉。但是或多或少能学到点东西,一些以前没有碰到过的东西。
首先:baidu了下spring源码解读,找到篇文章,跟着一步步看吧。
我也从 XmlBeanFactory入手吧。
首先让我碰到了未知的几个数据结构:ConcurrentHashMap,还有几个没怎么碰到的类
ClassLoader、ResourceLoader..,泛型之类的,记下来,以后一一baidu搞懂
还有篇文章分享下
http://www.ibm.com/developerworks/cn/java/j-lo-spring-principle/index.html
不错
真是望而生畏啊,一般人哪写得出这么多继承关系
....
....
把Resource转啊转,最后用BeanDefinitionParseDelegate去解析Document.然后一个一个注册.
/** * Parse the elements at the root level in the document: * "import", "alias", "bean". * @param root the DOM root element of the document */protected void parseBeanDefinitions(Element root, BeanDefinitionParserDelegate delegate) {if (delegate.isDefaultNamespace(delegate.getNamespaceURI(root))) {NodeList nl = root.getChildNodes();for (int i = 0; i < nl.getLength(); i++) {Node node = nl.item(i);if (node instanceof Element) {Element ele = (Element) node;String namespaceUri = delegate.getNamespaceURI(ele);if (delegate.isDefaultNamespace(namespaceUri)) {parseDefaultElement(ele, delegate);}else {delegate.parseCustomElement(ele);}}}}else {delegate.parseCustomElement(root);}}