zoukankan      html  css  js  c++  java
  • spring启动过程之源码跟踪(续beanfactory)spring Debug

    1.初始化过程

    1         Resource res = new ClassPathResource("/applicationContext.xml"); 
    2         XmlBeanFactory factory = new XmlBeanFactory(res); 

    2.入门

     1     /**
     2      * Create a new XmlBeanFactory with the given input stream,
     3      * which must be parsable using DOM.
     4      * @param resource XML resource to load bean definitions from
     5      * @param parentBeanFactory parent bean factory
     6      * @throws BeansException in case of loading or parsing errors
     7      */
     8     public XmlBeanFactory(Resource resource, BeanFactory parentBeanFactory) throws BeansException {
     9         super(parentBeanFactory);
    10         this.reader.loadBeanDefinitions(resource);
    11     }

    3.读取配置文件XmlBeanDefinitionReader.java

     1     public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefinitionStoreException {
     2         Assert.notNull(encodedResource, "EncodedResource must not be null");
     3         if (logger.isInfoEnabled()) {
     4             logger.info("Loading XML bean definitions from " + encodedResource.getResource());
     5         }
     6 
     7         Set currentResources = (Set) this.resourcesCurrentlyBeingLoaded.get();
     8         if (currentResources == null) {
     9             currentResources = new HashSet(4);
    10             this.resourcesCurrentlyBeingLoaded.set(currentResources);
    11         }
    12         if (!currentResources.add(encodedResource)) {
    13             throw new BeanDefinitionStoreException(
    14                     "Detected recursive loading of " + encodedResource + " - check your import definitions!");
    15         }
    16         try {
    17             InputStream inputStream = encodedResource.getResource().getInputStream();
    18             try {
    19                 InputSource inputSource = new InputSource(inputStream);
    20                 if (encodedResource.getEncoding() != null) {
    21                     inputSource.setEncoding(encodedResource.getEncoding());
    22                 }
    23                 return doLoadBeanDefinitions(inputSource, encodedResource.getResource());
    24             }
    25             finally {
    26                 inputStream.close();
    27             }
    28         }
    29         catch (IOException ex) {
    30             throw new BeanDefinitionStoreException(
    31                     "IOException parsing XML document from " + encodedResource.getResource(), ex);
    32         }
    33         finally {
    34             currentResources.remove(encodedResource);
    35             if (currentResources.isEmpty()) {
    36                 this.resourcesCurrentlyBeingLoaded.set(null);
    37             }
    38         }
    39     }

    4.读取方法DefaultBeanDefinitionDocumentReader.java

     1     /**
     2      * Parses bean definitions according to the "spring-beans" DTD.
     3      * <p>Opens a DOM Document; then initializes the default settings
     4      * specified at <code>&lt;beans&gt;</code> level; then parses
     5      * the contained bean definitions.
     6      */
     7     public void registerBeanDefinitions(Document doc, XmlReaderContext readerContext) {
     8         this.readerContext = readerContext;
     9 
    10         logger.debug("Loading bean definitions");
    11         Element root = doc.getDocumentElement();
    12 
    13         BeanDefinitionParserDelegate delegate = createHelper(readerContext, root);
    14 
    15         preProcessXml(root);
    16         parseBeanDefinitions(root, delegate);
    17         postProcessXml(root);
    18     }
  • 相关阅读:
    运行从别处复制过来的linux可执行程序
    查看linux服务器版本
    编码问题
    Programmer Dvorak键盘布局
    Ubuntu下安装JDK图文解析
    数据结构和算法设计专题之---24点游戏(穷举法和递归法)
    数据结构和算法设计专题之---单链表的逆序
    Android中实现静态的默认安装和卸载应用
    J2EE学习篇之--JQuery技术详解
    MyEclipse6.0中使用aptana插件,添加jquery提示功能
  • 原文地址:https://www.cnblogs.com/davidwang456/p/2956187.html
Copyright © 2011-2022 走看看