/**
* Perform a scan within the specified base packages,
* returning the registered bean definitions.
* <p>This method does <i>not</i> register an annotation config processor
* but rather leaves this up to the caller.
* @param basePackages the packages to check for annotated classes
* @return set of beans registered if any for tooling registration purposes (never {@code null})
*/protected Set<BeanDefinitionHolder>doScan(String... basePackages){
Assert.notEmpty(basePackages,"At least one base package must be specified");
Set<BeanDefinitionHolder> beanDefinitions =newLinkedHashSet<>();for(String basePackage : basePackages){//浏览包中的候选类
Set<BeanDefinition> candidates =findCandidateComponents(basePackage);for(BeanDefinition candidate : candidates){
ScopeMetadata scopeMetadata =this.scopeMetadataResolver.resolveScopeMetadata(candidate);
candidate.setScope(scopeMetadata.getScopeName());
String beanName =this.beanNameGenerator.generateBeanName(candidate,this.registry);if(candidate instanceofAbstractBeanDefinition){postProcessBeanDefinition((AbstractBeanDefinition) candidate, beanName);}if(candidate instanceofAnnotatedBeanDefinition){
AnnotationConfigUtils.processCommonDefinitionAnnotations((AnnotatedBeanDefinition) candidate);}if(checkCandidate(beanName, candidate)){
BeanDefinitionHolder definitionHolder =newBeanDefinitionHolder(candidate, beanName);
definitionHolder =
AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder,this.registry);
beanDefinitions.add(definitionHolder);registerBeanDefinition(definitionHolder,this.registry);}}}return beanDefinitions;}
1、ContextNamespaceHandlerpublic class ContextNamespaceHandler extends NamespaceHandlerSupport { public ContextNamespaceHandler() { } public void init() { this.registerBeanDefinit...