附录

XML模式

附录的这部分列出了数据访问的XML模式,包括以下内容:

tx模式

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

我们强烈建议您查看随Spring发行的'spring-tx.xsd'文件。该文件包含Spring事务配置的XML模式,并涵盖了tx命名空间中的所有各种元素,包括属性默认值和类似信息。该文件在内联文档中有记录,因此为了遵循DRY(不要重复自己)原则,这里不会重复提供信息。

为了完整起见,要使用tx模式中的元素,您需要在Spring XML配置文件的顶部添加以下前导信息。以下代码片段中的文本引用了正确的模式,以便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定义 -->

</beans>
1 声明使用tx命名空间。
2 指定位置(包括其他模式位置)。
通常,当您使用tx命名空间中的元素时,您还会使用aop命名空间中的元素(因为Spring中的声明式事务支持是通过AOP实现的)。上述XML片段包含了引用aop模式所需的相关行,以便aop命名空间中的元素对您可用。

jdbc模式

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

要使用jdbc模式中的元素,您需要在Spring XML配置文件的顶部添加以下前导信息。以下代码片段中的文本引用了正确的模式,以便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定义 -->

</beans>
1 声明使用jdbc命名空间。
2 指定位置(包括其他模式位置)。