附录

XML Schema

附录的这一部分列出了用于数据访问的 XML Schema,包括以下内容:

tx Schema

tx 标签用于配置 Spring 全面事务支持中的所有 Bean。这些标签在 事务管理 章节中介绍。

我们强烈建议您查看 Spring 分发包中附带的 'spring-tx.xsd' 文件。此文件包含 Spring 事务配置的 XML Schema,并涵盖了 tx 命名空间中的各种元素,包括属性默认值和类似信息。此文件有内联文档,因此,为了遵循 DRY(不要重复自己)原则,此处不再重复这些信息。

为了完整起见,要使用 tx Schema 中的元素,你需要在 Spring XML 配置文件顶部添加以下前导内容。以下代码片段中的文本引用了正确的 Schema,以便 tx 命名空间中的标签可用:

<?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:tx="http://www.springframework.org/schema/tx" (1)
	xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans
		https://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/tx
		https://www.springframework.org/schema/tx/spring-tx.xsd (2)
		http://www.springframework.org/schema/aop
		https://www.springframework.org/schema/aop/spring-aop.xsd">

	<!-- bean definitions here -->

</beans>
1 声明使用 tx 命名空间。
2 指定位置(以及其他 Schema 位置)。
通常,在使用 tx 命名空间中的元素时,你也会使用 aop 命名空间中的元素(因为 Spring 中的声明式事务支持是使用 AOP 实现的)。前面的 XML 代码片段包含了引用 aop Schema 所需的相关行,以便 aop 命名空间中的元素可用。

jdbc Schema

jdbc 元素允许你快速配置嵌入式数据库或初始化现有数据源。这些元素分别在 嵌入式数据库支持初始化 DataSource 中有文档说明。

要使用 jdbc Schema 中的元素,你需要在 Spring XML 配置文件顶部添加以下前导内容。以下代码片段中的文本引用了正确的 Schema,以便 jdbc 命名空间中的元素可用:

<?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:jdbc="http://www.springframework.org/schema/jdbc" (1)
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans
		https://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/jdbc
		https://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> (2)

	<!-- bean definitions here -->

</beans>
1 声明使用 jdbc 命名空间。
2 指定位置(以及其他 Schema 位置)。