web.servlet.HttpServletBean.init()
web.servlet.FrameworkServlet.initServletBean()
web.servlet.FrameworkServlet.initWebApplicationContext()
web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac)
context.support.AbstractApplicationContext.refresh()
context.support.AbstractApplicationContext.obtainFreshBeanFactory()
context.support.AbstractRefreshableApplicationContext.refreshBeanFactory()
web.context.support.XmlWebApplicationContext.loadBeanDefinitions(DefaultListableBeanFactory beanFactory)
或
web.context.support.AnnotationConfigWebApplicationContext.loadBeanDefinitions(DefaultListableBeanFactory beanFactory)
web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlBeanDefinitionReader reader)
beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(String location, Set actualResources)
beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(Resource… resources)
beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(Resource resource)
beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(EncodedResource encodedResource)
从EncodedResource中加载BeanDefinition
beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(InputSource inputSource, Resource resource)
从InputSource中加载BeanDefinition
1. Document doc = doLoadDocument(inputSource, resource); 获得Document
2. registerBeanDefinitions(doc, resource); 从获得Document加载BeanDefinition
beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(Document doc, Resource resource)
1. BeanDefinitionDocumentReader documentReader = createBeanDefinitionDocumentReader(); 获取BeanDefinitionDocumentReader
2. documentReader.registerBeanDefinitions(doc, createReaderContext(resource)); 利用BeanDefinitionDocumentReader加载BeanDefinition
beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(Document doc, XmlReaderContext readerContext)
1. Element root = doc.getDocumentElement(); 获取Document根元素
2. doRegisterBeanDefinitions(root); 从根元素开始加载BeanDefinition
beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(Element root)
1. if (!getReaderContext().getEnvironment().acceptsProfiles(specifiedProfiles)) 根据profile属性和上下文Environment判断是否要加载该Element
2. parseBeanDefinitions(root, this.delegate); 加载root元素
beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(Element root, BeanDefinitionParserDelegate delegate)
解析根元素
1. parseDefaultElement(ele, delegate); 解析默认元素
2. delegate.parseCustomElement(ele); 解析csutom元素
beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(Element ele, BeanDefinitionParserDelegate delegate)
解析默认元素:import alias bean beans
beans.factory.xml.DefaultBeanDefinitionDocumentReader.processBeanDefinition(Element ele, BeanDefinitionParserDelegate delegate)
解析bean元素beans.factory.xml.BeanDefinitionParserDelegate.parseBeanDefinitionElement(Element ele, BeanDefinition containingBean)
解析bean元素,生成BeanDefinitionHolder对象,该对象包含beanDefinition, beanName, aliasesArraybeans.factory.xml.BeanDefinitionParserDelegate.parseBeanDefinitionElement(Element ele, String beanName, BeanDefinition containingBean)
解析bean元素,生成AbstractBeanDefinition
beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(Element ele, BeanDefinition containingBd)
解析Custom命名空间的元素:
1. 根据命名空间URI找到解析器,命名空间URI和解析器的映射关系放在properties文件中。
2. 让解析器解析Element元素,返回BeanDefinition
- beans.factory.xml.DefaultNamespaceHandlerResolver.resolve(String namespaceUri)
根据URI解析找到命名空间解析器NamespaceHandler:Map<String, Object> handlerMappings = getHandlerMappings();
遍历所有properties文件,查找解析器