• 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     }
  • 相关阅读:
    Objective-C 【self的用法】
    Objective-C 学习笔记(Day 3,下)
    Objective-C 学习笔记(Day 3,上)
    Objective-C 学习笔记(Day 2)
    牵扯较多属性和方法的类题目,很简单的题目本来不想发的,如果有同学学到这个题目感觉太长不愿敲代码,copy走我的即可~不过还是建议自己打一打
    Objective-C 学习笔记(Day 1)
    输出一个等边三角形的字母阵,等边三角形的两腰为字母A,往里靠依次字母大一个(详细题目文章中描述)
    分类或者叫类别 oc
    自定义构造方法 initWithName: oc
    self = [super init] 拿出来单独讲讲
  • 原文地址:https://www.cnblogs.com/davidwang456/p/2956187.html
Copyright © 2020-2023  润新知