調用鏈路:java
registerBeanDefinition:861, DefaultListableBeanFactory (org.springframework.beans.factory.support) registerBeanDefinition:315, GenericApplicationContext (org.springframework.context.support) registerBeanDefinition:149, BeanDefinitionReaderUtils (org.springframework.beans.factory.support) registerBean:192, AnnotatedBeanDefinitionReader (org.springframework.context.annotation) registerBean:142, AnnotatedBeanDefinitionReader (org.springframework.context.annotation) register:131, AnnotatedBeanDefinitionReader (org.springframework.context.annotation) register:160, AnnotationConfigApplicationContext (org.springframework.context.annotation) <init>:83, AnnotationConfigApplicationContext (org.springframework.context.annotation)
源碼:spring
public void register(Class<?>... annotatedClasses) { for (Class<?> annotatedClass : annotatedClasses) { registerBean(annotatedClass); } } public void registerBean(Class<?> annotatedClass, String name, Class<? extends Annotation>... qualifiers) { AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(annotatedClass); if (this.conditionEvaluator.shouldSkip(abd.getMetadata())) { return; } ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(abd); abd.setScope(scopeMetadata.getScopeName()); String beanName = (name != null ? name : this.beanNameGenerator.generateBeanName(abd, this.registry)); AnnotationConfigUtils.processCommonDefinitionAnnotations(abd); if (qualifiers != null) { for (Class<? extends Annotation> qualifier : qualifiers) { if (Primary.class == qualifier) { abd.setPrimary(true); } else if (Lazy.class == qualifier) { abd.setLazyInit(true); } else { abd.addQualifier(new AutowireCandidateQualifier(qualifier)); } } } // 註冊配置類 BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(abd, beanName); definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry); BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, this.registry); }