Spring XML默认标签配置解析注册Bean源码分析(三)——Document对象

Spring的IOC容器初始化源码分析三:refresh(01) SpringIOC 容器对 Bean 定义资源的载入是从 refresh()函数开始的,refresh()是一个模板方法, refresh()方法的作用是:在创建 IOC 容器前,如果已经有容器存在,则需要把已有的容器销毁和关闭, 以保证在 refresh 之后使用的是新建立起来的 IOC 容器。refresh 的作用类似于对 IOC 容器的重启, 在新建立好的容器中对容器进行初始化,对 Bean... 阅读详情

3.3.1. Document对象

        我们之前说在BeanDefinition的解析注册过程中,需要将Resource文件资源转换为Document对象,这一节我们就来看一下Document doc = doLoadDocument(inputSource, resource);。

// 源码位置:org.springframework.beans.factory.xml.XmlBeanDefinitionReader#doLoadDocument
/**
 * Actually load the specified document using the configured DocumentLoader.
 * @param inputSource the SAX InputSource to read from
 * @param resource the resource descriptor for the XML file
 * @return the DOM Document
 * @throws Exception when thrown from the DocumentLoader
 * @see #setDocumentLoader
 * @see DocumentLoader#loadDocument
 */
protected Document doLoadDocument(InputSource inputSource, Resource resource) throws Exception {
	return this.documentLoader.loadDocument(inputSource, getEntityResolver(), this.errorHandler,
			getValidationModeForResource(resource), isNamespaceAware());
}
3.3.1.1. getValidationModeForResource

        在解析XML之前,我们首先需要对XML内容及格式进行验证,XML验证常用的模式有DTD和XSD两种。

DTD验证模式:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//Spring//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd" >

        我们可以把DTD(Document Type Definition)文件下载下来或在Spring的jar包spring-beans-5.1.8.RELEASE.jar!/org/springframework/beans/factory/xml/下找到spring-beans.dtd文件。查看内容我们发现,DTD文件用来定义XML,它使用一系列合法的元素来定义文档的结构。

XSD验证模式:

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

        我们可以通过网络在线查看XSD(XML Schema Definition)文件内容(点击查看)或在Spring的jar包中spring-beans-5.1.8.RELEASE.jar!/org/springframework/beans/factory/xml/spring-beans.xsd查看。XSD的作用也是定义一个XML文档结构,和DTD的作用一样,由于其比DTD更强大,可以替代DTD。

        我们在使用XSD定义XML文档的时候,我们需要在XML中声明:

  • 命名空间:
    xmlns="http://www.springframework.org/schema/beans"
  • 该命名空间对应的XSD位置:
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"它包括两部分,前一部分是命名空间的URI,后一部分是该命名空间所对应的XSD文件位置或URL位置。

上述不论是DTD还是XSD,我们不对其内容和使用做过多的解释,我们只需要知道,他们都是用来定义XML文档结构的语言,Spring将用他们来验证XML的合法性。

        Spring通过getValidationModeForResource(resource)判断文档的验证模式是DTD还是XSD。

// 源码位置:org.springframework.beans.factory.xml.XmlBeanDefinitionReader#getValidationModeForResource
/**
 * Determine the validation mode for the specified {@link Resource}.
 * If no explicit validation mode has been configured, then the validation
 * mode gets {@link #detectValidationMode detected} from the given resource.
 * <p>Override this method if you would like full control over the validation
 * mode, even when something other than {@link #VALIDATION_AUTO} was set.
 * @see #detectValidationMode
 */
protected int getValidationModeForResource(Resource resource) {
	// 如果指定了验证模式,则直接返回
	int validationModeToUse = getValidationMode();
	if (validationModeToUse != VALIDATION_AUTO) {
		return validationModeToUse;
	}
	// 否则继续判断验证模式
	int detectedMode = detectValidationMode(resource);
	if (detectedMode != VALIDATION_AUTO) {
		return detectedMode;
	}
	// 如果判断后仍然返回了VALIDATION_AUTO,那么尝试使用XSD模式验证
	// Hmm, we didn't get a clear indication... Let's assume XSD,
	// since apparently no DTD declaration has been found up until
	// detection stopped (before finding the document's root tag).
	return VALIDATION_XSD;
}

        我们对int detectedMode = detectValidationMode(resource);继续展开。在这里,Spring将通过resource.getInputStream()获取到XML资源文件的输入流,然后交给XmlValidationModeDetector的detectValidationMode(InputStream inputStream)方法做实际判断操作(XmlValidationModeDetector类就是专职做这个的)。

// 源码位置:org.springframework.util.xml.XmlValidationModeDetector#detectValidationMode
/**
 * Detect the validation mode for the XML document in the supplied {@link InputStream}.
 * Note that the supplied {@link InputStream} is closed by this method before returning.
 * @param inputStream the InputStream to parse
 * @throws IOException in case of I/O failure
 * @see #VALIDATION_DTD
 * @see #VALIDATION_XSD
 */
public int detectValidationMode(InputStream inputStream) throws IOException {
	// Peek into the file to look for DOCTYPE.
	BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
	try {
		boolean isDtdValidated = false;
		String content;
		while ((content = reader.readLine()) != null) {
			content = consumeCommentTokens(content);
			if (this.inComment || !StringUtils.hasText(content)) {
				continue;
			}
			// 是否包含“DOCTYPE”关键字,包含就是DTD模式
			if (hasDoctype(content)) {
				isDtdValidated = true;
				break;
			}
			// 标签“<”符号的下一个字符是否是字母,如果是字母则返回true
			if (hasOpeningTag(content)) {
				// End of meaningful data...
				break;
			}
		}
		return (isDtdValidated ? VALIDATION_DTD : VALIDATION_XSD);
	}
	catch (CharConversionException ex) {
		// Choked on some character encoding...
		// Leave the decision up to the caller.
		return VALIDATION_AUTO;
	}
	finally {
		reader.close();
	}
}

         上面的代码我们很容易看出Spring的校验逻辑,就是看XML中是否包含“DOCTYPE”关键字,如果包含就是DTD,否则就是XSD。

3.3.1.2. getEntityResolver

         getEntityResolver()方法返回一个EntityResolver对象,他是解析实体的基本接口。根据EntityResolver接口源码中的注释说明,如果 SAX 应用程序需要实现自定义处理外部实体,则必须实现此接口并使用setEntityResolver方法(比如DocumentBuilder类中的setEntityResolver方法)向 SAX 驱动器注册一个实例。然后 XML 读取器将允许应用程序在包含外部实体之前截取任何外部实体(包括外部 DTD 子集和外部参数实体,如果有)。许多 SAX 应用程序不需要实现此接口,但对于从数据库或其他特定的输入源中构建 XML 文档的应用程序,或者对于使用 URI 类型(而不是 URL )的应用程序,这特别有用。以上是官方的解释,就是说,对于解析一个XML,SAX首先读取的是XML文档上的声明,根据声明寻找相应的DTD/XSD定义,以便对文档进行校验。默认是通过网络来下载相应的DTD/XSD声明(DTD请参考XML的<!DOCTYPE部分,XSD请参考XML的xsi:schemaLocation部分),并进行验证,但是当网络不通畅的时候就会报错。Spring实现了EntityResolver接口,其目的就是提供一个在本地寻找DTD/XSD的方法,以避免网络寻找所代理的弊端。下面我们看一下具体的实现。

public abstract InputSource resolveEntity (String publicId,
                                           String systemId)
    throws SAXException, IOException;

        EntityResolver接口只用一个方法InputSource resolveEntity (String publicId, String systemId),两个参数:

  • publicId:外部实体的公共标识符,如果没有提供,则为NULL。
  • systemId:要引用的外部实体的系统标识符。
  • return InputSource:返回一个InputSource对象,即本地DTD/XSD文档。

publicId举例:
DTD模式 = -//Spring//DTD BEAN 2.0//EN
XSD模式 = NULL


systemId举例:
DTD模式 = http://www.springframework.org/dtd/spring-beans-2.0.dtd
XSD模式 = http://www.springframework.org/schema/beans/spring-beans.xsd

        随后创建ResourceEntityResolver对象:

// 源码位置:org.springframework.beans.factory.xml.XmlBeanDefinitionReader#getEntityResolver
/**
 * Return the EntityResolver to use, building a default resolver
 * if none specified.
 */
protected EntityResolver getEntityResolver() {
	if (this.entityResolver == null) {
		// Determine default EntityResolver to use.
		ResourceLoader resourceLoader = getResourceLoader();
		if (resourceLoader != null) {
			this.entityResolver = new ResourceEntityResolver(resourceLoader);
		}
		else {
			this.entityResolver = new DelegatingEntityResolver(getBeanClassLoader());
		}
	}
	return this.entityResolver;
}

        ResourceEntityResolver继承至DelegatingEntityResolver,DelegatingEntityResolver实现了EntityResolver接口,ResourceEntityResolver类对父类InputSource resolveEntity (String publicId, String systemId)方法进行了重写:

// 源码位置:org.springframework.beans.factory.xml.ResourceEntityResolver#resolveEntity
@Override
@Nullable
public InputSource resolveEntity(@Nullable String publicId, @Nullable String systemId)
		throws SAXException, IOException {

	// 这里调用了父类的resolveEntity方法。
	InputSource source = super.resolveEntity(publicId, systemId);

	if (source == null && systemId != null) {
		// 此处省略。。。
	}
	return source;
}

        我们可以看到InputSource source = super.resolveEntity(publicId, systemId);实际的InputSource返回由其父类完成。

// 源码位置:org.springframework.beans.factory.xml.DelegatingEntityResolver#resolveEntity
@Override
@Nullable
public InputSource resolveEntity(@Nullable String publicId, @Nullable String systemId)
		throws SAXException, IOException {

	if (systemId != null) {
		if (systemId.endsWith(DTD_SUFFIX)) {
			return this.dtdResolver.resolveEntity(publicId, systemId);
		}
		else if (systemId.endsWith(XSD_SUFFIX)) {
			return this.schemaResolver.resolveEntity(publicId, systemId);
		}
	}

	// Fall back to the parser's default behavior.
	return null;
}

        在这里我们终于看到了DTD和XSD不同模式下的不同处理。

dtdResolver = new BeansDtdResolver();// DTD模式
schemaResolver = new PluggableSchemaResolver(classLoader);// XSD模式
// 它们都实现EntityResolver接口

由于BeansDtdResolver和PluggableSchemaResolver都实现EntityResolver接口,必然有InputSource resolveEntity (String publicId, String systemId)方法,我们只需要看着两个类是如何实现的该方法,就清楚DTD/XSD模式是如何找到本地的定义文档的。

// 源码位置org.springframework.beans.factory.xml.BeansDtdResolver#resolveEntity

private static final String DTD_EXTENSION = ".dtd";

private static final String DTD_NAME = "spring-beans";

@Override
@Nullable
public InputSource resolveEntity(@Nullable String publicId, @Nullable String systemId) throws IOException {
	if (logger.isTraceEnabled()) {
		logger.trace("Trying to resolve XML entity with public ID [" + publicId +
				"] and system ID [" + systemId + "]");
	}

	if (systemId != null && systemId.endsWith(DTD_EXTENSION)) {
		int lastPathSeparator = systemId.lastIndexOf('/');
		int dtdNameStart = systemId.indexOf(DTD_NAME, lastPathSeparator);
		if (dtdNameStart != -1) {
			String dtdFile = DTD_NAME + DTD_EXTENSION;
			if (logger.isTraceEnabled()) {
				logger.trace("Trying to locate [" + dtdFile + "] in Spring jar on classpath");
			}
			try {
				Resource resource = new ClassPathResource(dtdFile, getClass());
				InputSource source = new InputSource(resource.getInputStream());
				source.setPublicId(publicId);
				source.setSystemId(systemId);
				if (logger.isTraceEnabled()) {
					logger.trace("Found beans DTD [" + systemId + "] in classpath: " + dtdFile);
				}
				return source;
			}
			catch (FileNotFoundException ex) {
				if (logger.isDebugEnabled()) {
					logger.debug("Could not resolve beans DTD [" + systemId + "]: not found in classpath", ex);
				}
			}
		}
	}

	// Fall back to the parser's default behavior.
	return null;
}

        上面是DTD模式,根据String dtdFile = DTD_NAME + DTD_EXTENSION;我知道是BeansDtdResolver类所在目录下找spring-beans.dtd文件。

@Override
@Nullable
public InputSource resolveEntity(@Nullable String publicId, @Nullable String systemId) throws IOException {
	if (logger.isTraceEnabled()) {
		logger.trace("Trying to resolve XML entity with public id [" + publicId +
				"] and system id [" + systemId + "]");
	}

	if (systemId != null) {
		String resourceLocation = getSchemaMappings().get(systemId);
		if (resourceLocation == null && systemId.startsWith("https:")) {
			// Retrieve canonical http schema mapping even for https declaration
			resourceLocation = getSchemaMappings().get("http:" + systemId.substring(6));
		}
		if (resourceLocation != null) {
			Resource resource = new ClassPathResource(resourceLocation, this.classLoader);
			try {
				InputSource source = new InputSource(resource.getInputStream());
				source.setPublicId(publicId);
				source.setSystemId(systemId);
				if (logger.isTraceEnabled()) {
					logger.trace("Found XML schema [" + systemId + "] in classpath: " + resourceLocation);
				}
				return source;
			}
			catch (FileNotFoundException ex) {
				if (logger.isDebugEnabled()) {
					logger.debug("Could not find XML schema [" + systemId + "]: " + resource, ex);
				}
			}
		}
	}

	// Fall back to the parser's default behavior.
	return null;
}

        上面是XSD模式,从String resourceLocation = getSchemaMappings().get(systemId);中我们可以看到它是从一个映射关系中,根据systemId找到本地的XSD定义文档。那么我们看一个这映射关系从哪里来。

// 源码位置:org.springframework.beans.factory.xml.PluggableSchemaResolver#resolveEntity

public static final String DEFAULT_SCHEMA_MAPPINGS_LOCATION = "META-INF/spring.schemas";

public PluggableSchemaResolver(@Nullable ClassLoader classLoader) {
	this.classLoader = classLoader;
	this.schemaMappingsLocation = DEFAULT_SCHEMA_MAPPINGS_LOCATION;
}

/**
 * Load the specified schema mappings lazily.
 */
private Map<String, String> getSchemaMappings() {
	Map<String, String> schemaMappings = this.schemaMappings;
	if (schemaMappings == null) {
		synchronized (this) {
			schemaMappings = this.schemaMappings;
			if (schemaMappings == null) {
				if (logger.isTraceEnabled()) {
					logger.trace("Loading schema mappings from [" + this.schemaMappingsLocation + "]");
				}
				try {
					Properties mappings =
							PropertiesLoaderUtils.loadAllProperties(this.schemaMappingsLocation, this.classLoader);
					if (logger.isTraceEnabled()) {
						logger.trace("Loaded schema mappings: " + mappings);
					}
					schemaMappings = new ConcurrentHashMap<>(mappings.size());
					CollectionUtils.mergePropertiesIntoMap(mappings, schemaMappings);
					this.schemaMappings = schemaMappings;
				}
				catch (IOException ex) {
					throw new IllegalStateException(
							"Unable to load schema mappings from location [" + this.schemaMappingsLocation + "]", ex);
				}
			}
		}
	}
	return schemaMappings;
}

        getSchemaMappings()去加载systemId与本地XSD定义文档的映射关系。Properties mappings = PropertiesLoaderUtils.loadAllProperties(this.schemaMappingsLocation, this.classLoader);这里schemaMappingsLocation=META-INF/spring.schemas,因此我们找到了配置映射关系的文件在META-INF/spring.schemas里面,打开该文件我们看到了映射关系:

http\://www.springframework.org/schema/beans/spring-beans-2.0.xsd=org/springframework/beans/factory/xml/spring-beans.xsd
http\://www.springframework.org/schema/beans/spring-beans-2.5.xsd=org/springframework/beans/factory/xml/spring-beans.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.0.xsd=org/springframework/beans/factory/xml/spring-beans.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.1.xsd=org/springframework/beans/factory/xml/spring-beans.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.2.xsd=org/springframework/beans/factory/xml/spring-beans.xsd
http\://www.springframework.org/schema/beans/spring-beans-4.0.xsd=org/springframework/beans/factory/xml/spring-beans.xsd
http\://www.springframework.org/schema/beans/spring-beans-4.1.xsd=org/springframework/beans/factory/xml/spring-beans.xsd
... ...
... ...
... ...略
3.3.1.3. Document对象的加载

        回到开篇的代码片段:

// 源码位置:org.springframework.beans.factory.xml.XmlBeanDefinitionReader#doLoadDocument
/**
 * Actually load the specified document using the configured DocumentLoader.
 * @param inputSource the SAX InputSource to read from
 * @param resource the resource descriptor for the XML file
 * @return the DOM Document
 * @throws Exception when thrown from the DocumentLoader
 * @see #setDocumentLoader
 * @see DocumentLoader#loadDocument
 */
protected Document doLoadDocument(InputSource inputSource, Resource resource) throws Exception {
	return this.documentLoader.loadDocument(inputSource, getEntityResolver(), this.errorHandler,
			getValidationModeForResource(resource), isNamespaceAware());
}

        我们已经清楚了加载Document对象的关键参数getValidationModeForResource(resource)和getEntityResolver(),上面的this.documentLoader是DefaultDocumentLoader对象,通过调用其loadDocument方法,最终我们完成了Document对象产生的工作。

总结Spring中XML资源配置转Document对象的主要工作,一是判断DTD/XSD验证模式;二是这两种模式下在本地能找到DTD/XSD定义文档,摆脱网络访问造成的脱机问题; 剩下的工作就交给JDK的XML解析工具来完成了。

wincc 服务器授权型号,WinCC V7.5 SP1软件安装及授权方法 上篇教程给大家介绍了TIA Portal V16 安装方法,今天分享一下WinCC V7.5 SP1。目前V7.5 SP1是WinCC最新的版本,发布时间2019年11月13日。先放一个官网对WinCC V7.5 的介绍视频,感兴趣的可以先看一下。1、软件下载官网下载链接:https://support.industry.siemens.com/cs/document/109772879五个文件下... 阅读详情

相关推荐

idea 编译打包nacos2.0.3源码,生成可执行jar 包常见问题

idea 编译打包nacos2.0.3源码,生成可执行jar 包常见问题

fyihdg的专栏 1226

spring源码中流InputSource 转化成 Document过程

spring源码中流InputSource 转化成 Document过程分享

nandao158的博客 1278

别再死磕DH参数了!用MATLAB Robotics Toolbox + SOLIDWORKS搞定六轴机械臂仿真(附避坑指南)

本文详细介绍了如何利用MATLAB Robotics Toolbox和SOLIDWORKS进行六轴机械臂仿真,避免常见的DH参数错误和模型导出问题。通过实战指南和避坑技巧,帮助工程师实现从三维建模到运动学仿真的无缝衔接,提升仿真效率和准确性。

weixin_27066963的博客 400

XML关键字

SGML--Standard Generalized Marked Language 标准通用标记语言GML--Generalized Marked Language 通用标记语言XML--Extesible Markup Language 可扩展标记语言SAX--Simple API for XML,由XML-DEV邮件列表的成员开发的处理XML的接口DOM--Document Object M

随想,随记 8643

麒麟V10服务器多硬盘安装与分区实战:告别自动分区,手动分配/boot、swap和/根目录

本文详细介绍了麒麟V10服务器在多硬盘环境下的手动分区策略,包括/boot、swap和/根目录的优化分配方案。通过SSD与HDD混合存储架构的合理规划,提升系统性能和运维效率,适用于企业级定制化系统部署需求。

weixin_26976635的博客 415

《Arduino与LabVIEW开发实战》第2章 LabVIEW基础

第2章 LabVIEW基础 2.1 LabVIEW与虚拟仪器 2.1.1 什么是虚拟仪器 仪器仪表发展方向有很多,其中一个重要方向是将计算机和仪器结合起来。具体来说有两种方式,一种是将微处理器或微控制器嵌入到仪器中,构建智能化的内含嵌入式系统的仪器仪表,这是嵌入式仪器;另一种是将仪器装入计算机中,以通用计算机硬件及操作系统为载体,外配数据采集卡等外部设备,通过编制不同功能的程序,以实现多种仪...

jxgy01的博客 495

Spring IoC的细节--XmlBeanDefinitionReader.doLoadDocument(InputSource inputSource, Resource resource)

参考博客:https://blog.csdn.net/lyc_liyanchao/article/details/83004510 XmlBeanDefinitionReader: protected int doLoadBeanDefinitions(InputSource inputSource, Resource resource) throws BeanDefinitionStore...

aidaowuqiong的博客 509

S/4HANA Private Cloud 与 On-Premise 的 Key User Custom Fields 运输与升级避坑指南

本文探讨了SAP S/4HANA Cloud Private Edition和On-Premise系统中Key User Custom Fields的管理要点。文章指出,Custom Fields涉及元数据生成、对象一致性、传输治理等完整链路,操作不当会导致字段丢失或升级失败。关键建议包括:使用ATO Fiori App管理扩展项与传输绑定,配置正确的job user权限,避免在多系统并行开发同一字段。特别强调升级时需执行CFD_REGENERATE_IN_ONPREMISE报表,并通过标准传输机制推进变更

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 203

Spring4.3.x 浅析xml配置的解析过程(3)——使用DocumentLoader创建Document对象

准备工作Spring的XmlBeanDefinitionReader通过ResourceLoader创建了Resource对象后,又如何处理Resource对象呢?XmlBeanDefinitionReader拿到Resource对象后,会调用它的loadBeanDefinitions(Resource resource)方法,下面我们就根据这个方法为入口来探讨这个问题,见下面的代码。 pub

chyohn的博客 2512

【人工智能】广度优先搜索(BFS)在人工智能中的应用(Python源码)

本文系统阐述了广度优先搜索(BFS)算法在人工智能领域的核心原理与应用。作为无信息搜索算法,BFS通过FIFO队列实现节点遍历,保证在无权图中的最优性。文章详细解析了BFS的伪代码实现和Python编程示例,并通过机器人路径规划案例展示了其实际应用场景。测试结果表明,BFS能有效解决包含障碍物的网格寻路问题,验证了算法在AI领域的实用价值。该研究为理解基础搜索算法及其工程应用提供了重要参考。

梦想起飞的地方 1150

lammps教程:实例讲解npt、nvt系综的选择

对于lammps新手来说,系综的选择令人困惑,到底是应该用nvt系综还是npt系综? 我在初学lammps时就被这个问题困扰了很久。如果去问别人,可能会告诉你一个答案:根据模拟需要确定。 其实和没说一样。 到底如何确定系综,确实不是一句两句能够说清楚的,不同的体系、不同的模拟目的要选择不同的系综。 前几天遇到的一个合金的模拟案例,比较有代表性,分享出来供大家参考。 建模方法和之前介绍过的高熵合金建模方法类似,先建立单晶模型,然后使用替换原子的命令获得合金结构。 建模完成后,按照常规,先上nvt系综进行驰豫

lammps_jiayou的博客 9775

Spring读源码系列02----默认标签解析过程

Spring读源码系列02----默认标签解析过程Bean标签的解析及注册processBeanDefinition----对Bean标签进行处理的方法BeanDefinitionParserDelegate#parseBeanDefinitionElement从xml配置信息--->BeanDefinitionBeanDefinitionParserDelegate#parseBeanDefinitionElement---将bean标签映射到BeanDefinitionBeanDefinition

m0_53157173的博客 1334

Go语言爬虫:chromedp 的详细使用

chromedp 是 Go 语言中无头浏览器自动化的终极利器。它能驱动真实的 Chrome 浏览器,处理 JavaScript 渲染、复杂交互和反爬虫机制

数据知道的博客 4503

死磕Spring之IoC篇 - BeanDefinition 的解析阶段(XML 文件)

该系列文章是本人在学习 Spring 的过程中总结下来的,里面涉及到相关源码,可能对读者不太友好,请结合我的源码注释 Spring 源码分析 GitHub 地址 进行阅读 Spring 版本:5.1.14.RELEASE 开始阅读这一系列文章之前,建议先查看《深入了解 Spring IoC(面试题)》这一篇文章 该系列其他文章请查看:《死磕 Spring 之 IoC 篇 - 文章导读》 BeanDefinition 的解析阶段(XML 文件) 上一篇文章《BeanDefinition 的加载阶段(XML 文

chinaherolts2008的博客 164

InTheHand.Net.Personal+BlueTooth4,蓝牙开发

项目中有蓝牙开发的必备dll,现在网上相关的文档博客不少,有的说的多有的说少,但是却很少有这两个dll,分享一下。

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

spring bean 的加载机制(源码分析)

xml的读取应该是Spring的重要功能,因为Spring的大部分功能都是以配置做为切入点的。 我们在静态代码块中读取配置文件可以这样做: //这样来加载配置文件 XmlBeanFactory factory = new XmlBeanFactory(new ClassPathRes...

weixin_34307464的博客 115

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

(一)Spring IoC源码-1.容器的初始化-03获取Document实例

在上篇文章IoC容器源码-容器的基础的末尾,我们讲到了“加载Xml文件,并封装成Document 实例”是通过Document doc = doLoadDocument(inputSource, resource);来完成的。本文将详细讲解doLoadDocument方法是如何获取Document的。 org.springframework.beans.factory.xml.XmlBeanDe...

潘威威的博客 943

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

2.菜鸟总结spring源码——获取Document

1.上一篇文档大概回顾了Resource resource = new ClassPathResource("beanFactoryTest.xml")的加载机制;    本次回顾从BeanFactory factory = new XmlBeanFactory(resource);这句话开始;    public XmlBeanFactory(Resource resource, BeanF

weixin_38068301的博客 378

Spring源码——BeanFactory 注册bean

XmlBeanFactory 继承DefaultListableBeanFactory,实现通过XML读取的方式来获取Bean的定义。 XmlBeanFactory维护一个XmlbeanDefinitionReader来加载需要的resource解析出的BeanDefinition。 XmlBeanFactory构造方法如下: /** * Create a new X

Mergades 826

Spring IOC:obtainFreshBeanFactory调用链

obtainFreshBeanFactory 方法会解析所有 Spring 配置文件(即我们在前文中介绍的contextConfigLocation配置),将所有 Spring 配置文件中的 bean 定义封装成 BeanDefinition,加载到 BeanFactory 中。

CRUD工程师 547

XmlValidationModeDetector源码分析

总结:验证 spring 的 是需要 DTD 模式还是 XSD模式,如果包含DOCTYPE表示 DTD模式 ,返回 2 表示 DTD验证模式,3 表示 XSD模式 具体看代码中注释 package org.springframework.util.xml; import java.io.BufferedReader; import java.io.CharConversionExc...

ruanhao1203的专栏 232

xmlBeanFactory源码解析

一.xmlBeanFactory结构 先来看看怎么用 我们可以使用xmlBeanFactory把spring使用起来,代码如下: ClassPathResource classPathResource = new ClassPathResource("spring2.xml"); XmlBeanFactory xmlBeanFactory = new XmlBean...

p13132312312的博客 519

Bean的加载原理

0. Bean 加载原理 加载过程: 通过 ResourceLoader和其子类 DefaultResourceLoader完成资源文件位置定位,实现从类路径,文件系统,url等方式定位功能,完成定位后得到 Resource对象,再交给 BeanDefinitionReader,它再委托给 BeanDefinitionParserDelegate完成bean的解析并得到 BeanDefiniti...

小马过河 924

spring5 源码深度解析----- IOC 之 容器的基本实现

概述 上一篇我们搭建完Spring源码阅读环境,spring源码深度解析—Spring的整体架构和环境搭建这篇我们开始真正的阅读Spring的源码,分析spring的源码之前我们先来简单回顾下spring核心功能的简单使用 容器的基本用法 bean是spring最核心的东西,spring就像是一个大水桶,而bean就是水桶中的水,水桶脱离了水也就没有什么用处了,我们简单看下bea...

weixin_30294709的博客 237

Spring源码解析之AOP篇(三)----Spring开启AOP的两种方式

一.基于XML的方式 在Spring的早些版本,流行的Xml的配置方式。只要在xml中配置对的标签以及属性,Spring就会帮我们解析。 <!--开启自动扫描--> <context:component-scan base-package="com.seaway.curatorframework"/> <!--开启自动代理--> ...

疾风丶Sao年的IT博客 460

XML的验证模式

前言   上一篇文章讲述了bean的加载的最关键的三个步骤,这三个步骤很重要,是支撑着Spring容器实现的基础,所以这三个步骤是值得仔细认真的去学习的,其中第一个步骤就是获取XML的验证模式,这篇文章就是讲述这个步骤。 DTD和XSD DTD:   DTD(Document Type Definition)即文档类型定义。是一种XML约束模式语言,是XML文件的验证机制,属于XML文件组...

weixin_30851409的博客 198

Spring源码解析(一)

终于下定决心,啃spring源码,主要是通过源码了解spring底层机制,以及学习一下编码技巧,其中肯定会有错误,希望大家指正,一起学习。好了,开始进入正题。我们的源码学习就是从下面这行代码开始:BeanFactory bf=new XmlBeanFactory(new ClassPathResource("beanFactoryTest.xml"));首先通过ClassPathResource的...

NEU_tt的博客 459
上一篇: Spring XML默认标签配置解析注册Bean源码分析(二)——Resource资源准备
下一篇: Spring XML默认标签配置解析注册Bean源码分析(四)——BeanDefinitionDocumentReader
舞键作歌
博客等级 码龄17年 18粉丝 23原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值