Sprign解析xml配置使用dom4j.第一步:获取Documentpublic class DocumentHelper{ //声明map存放节点 private Map<String, Document> docs = new HashMap<String, Document>(); public Document getDocument(String filePath) { //用HashMap先根据路径获取文档 Document doc=this.docs.get(filePath); if (doc==null) { //dom4j的解析得到doc … this.docs.put(filePath, doc); //如果为空,把路径和文档放进去 } return this.docs.get(filePath); }}第二步:获取Elementpublic class ElementHelper{ //声明map存放节点 private Map<String, Element> elements=new HashMap<String, Element>(); //往集合增加元素 public void addElements(Document doc) { //获取document的elements节点,并且放入集合中 … } //获取集合元素 public Element getElement(String id) { return elements.get(id);}//获取所有的元素Collection<Element> getElements(){…}}第三步:Bean的创造public class BeanCreatorHelper{ //空构造器 public Object createBeanUseDefaultConstruct(String className) { return = Class.forName(className).newInstance(); } //执行方法 … //其他set方法还原等等 …}第四步:applicationContext简单实现public class ApplicationContextHelper { protected ElementHelper elementHelper = new ElementHelper(); protected Map<String, Object> beans = new HashMap<String, Object>(); //获取具体的对象实例,也是我们使用Spring框架中用的最多的一个方法 public Object getBean(String id) { Object bean = this.beans.get(id); if (bean == null) { //1、获取到配置文件中的节点 Element e = elementHelper.getElement(id); //2、通过bean创造器BeanCreatorHelper,通过反射机制获得对象,并且放到map集合中。 … } return bean;}总结从Document的创造,再到Element的创建,再到解析Element,到applicationContext的实现。这一过程在编码中是按照顺序进行的,是不可逆的。真正的代码结构远比我上面提到的要复杂的很多。比如applicationContextHelper中,还有其他的自动注入方法等等,需要更深入的了解。