標籤解析入口
org.springframework.context.annotation.ComponentScanBeanDefinitionParser
主方法很簡潔,如下
public BeanDefinition parse(Element element, ParserContext parserContext) {
String[] basePackages = StringUtils.tokenizeToStringArray(element.getAttribute(BASE_PACKAGE_ATTRIBUTE),
ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
// Actually scan for bean definitions and register them.
ClassPathBeanDefinitionScanner scanner = configureScanner(parserContext, element);
Set<BeanDefinitionHolder> beanDefinitions = scanner.doScan(basePackages);
registerComponents(parserContext.getReaderContext(), beanDefinitions, element);
return null;
}
1、獲得需要掃描的路徑集合,這個是根據base-package配置來計算出來的
2、實例化一個掃描器,這裏返回的實例是:ClassPathBeanDefinitionScanner 對象
3、掃描獲得bean定義
4、向容器中註冊這些bean定義