Spring Spring parsing XML source code learning process ---

Spring loading of XML configuration files

Reference: "Spring Source depth analysis"

Environment to build needed: spring-core, spring-beans

Generally the most common use BeanFactory Get Bean as follows (XmlBeanFactory now abandoned)

public void testLoad(){
	BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("filePath"));
    ObjectBean oBean = (ObjectBean)beanFactory.getBean("beanName");
}

xml file written as

<?xml  version="1.0"  encoding="UTF-8"?>
<beans  xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd">

    <bean id="beanName" class="Beans.MyTestBean"/>

</beans>

其中XmlBeanFactory继承自DefaultListableBeanFactory(Bean加载的核心类)
DefaultListableBeanFactory(Bean加载的核心部分):综合下面的所有功能,主要是对bean注册后的处理
		extends: 
			AbstractAutowireCapableBeanFactory
				AbstractBeanFactory
				ConfigurableBeanFactory(1):提供配置Factory的各种方法
		implements:
			ConfigurableListableBeanFactory
				AutowireCapableBeanFactory:提供创建bean,自动注入,初始化及应用bean后的处理器
				ConfigurableBeanFactory(1)同
				ListableBeanFactory:根据各种条件获取bean的配置清单
			BeanDefinitionRegistry
				AliasRegistry:定义alias的简单增删改查等操作
			Serializable
The first step: Read Bean configuration file (XML)

a ClassPathResource new new ( "filename");
ClassPathResource class inheritance structurea ClassPathResource (String filename) method, by passing the file name, the file contents of the InputStream package, and record other information.Spring Resources through the interface abstracts the internal use of resources Spring: File, URL, ClassPath. The InputStream incoming XmlBeanFactory () in.

Step Two: Start treatment InputStream

new XmlBeanFactory (Resource resource) passing a simplified here Resource Object

The third step: Parse Document, registered Bean
The overall process:

Overall execution flow

Published 30 original articles · won praise 0 · Views 824

Guess you like

Origin blog.csdn.net/fantow/article/details/104756811