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

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

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

   Set configClasses = new LinkedHashSet(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 oldCandidateNames = new HashSet(Arrays.asList(candidateNames));
      Set alreadyParsedClasses = new HashSet();
      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实例化加载核心逻辑)