美文网首页
spring-boot bean实例化加载核心逻辑

spring-boot bean实例化加载核心逻辑

作者: edgar_chan | 来源:发表于2018-08-28 20:40 被阅读0次

spring-boot bean实例化加载核心逻辑

do {
   parser.parse(candidates);
   parser.validate();

   Set<ConfigurationClass> configClasses = new LinkedHashSet<ConfigurationClass>(parser.getConfigurationClasses());
   configClasses.removeAll(alreadyParsed);

   // Read the model and create bean definitions based on its content
   if (this.reader == null) {
      this.reader = new ConfigurationClassBeanDefinitionReader(
            registry, this.sourceExtractor, this.resourceLoader, this.environment,
            this.importBeanNameGenerator, parser.getImportRegistry());
   }
   this.reader.loadBeanDefinitions(configClasses);
   alreadyParsed.addAll(configClasses);

   candidates.clear();
   if (registry.getBeanDefinitionCount() > candidateNames.length) {
      String[] newCandidateNames = registry.getBeanDefinitionNames();
      Set<String> oldCandidateNames = new HashSet<String>(Arrays.asList(candidateNames));
      Set<String> alreadyParsedClasses = new HashSet<String>();
      for (ConfigurationClass configurationClass : alreadyParsed) {
         alreadyParsedClasses.add(configurationClass.getMetadata().getClassName());
      }
      for (String candidateName : newCandidateNames) {
         if (!oldCandidateNames.contains(candidateName)) {
            BeanDefinition beanDef = registry.getBeanDefinition(candidateName);
            if (ConfigurationClassUtils.checkConfigurationClassCandidate(beanDef, this.metadataReaderFactory) &&
                  !alreadyParsedClasses.contains(beanDef.getBeanClassName())) {
               candidates.add(new BeanDefinitionHolder(beanDef, candidateName));
            }
         }
      }
      candidateNames = newCandidateNames;
   }
}
while (!candidates.isEmpty());

相关文章

网友评论

      本文标题:spring-boot bean实例化加载核心逻辑

      本文链接:https://www.haomeiwen.com/subject/tcxcwftx.html