此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Framework 6.2.0! |
附录
XML 架构
附录的这一部分列出了用于数据访问的 XML 架构,包括以下内容:
这tx
图式
这tx
标记处理在 Spring 的全面支持中配置所有这些 bean
进行交易。这些标签在标题为 Transaction Management 的章节中介绍。
我们强烈建议您查看'spring-tx.xsd' 文件,该文件随
Spring 发行版。此文件包含 Spring 事务的 XML Schema
配置,并涵盖tx 命名空间,包括
属性默认值和类似信息。此文件以内联方式记录,因此,
为了遵守 DRY (不要
Repeat Yourself) 原则。 |
为了完整起见,要使用tx
schema 中,您需要具有
以下 preamble 位于 Spring XML 配置文件的顶部。的
以下代码段引用了正确的架构,以便tx
Namespace
可供您使用:
<?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 Namespace。 |
2 | 指定位置(包含其他架构位置)。 |
通常,当您使用tx 命名空间,您也在使用
元素aop 命名空间(因为 Spring 中的声明式事务支持是
使用 AOP 实现)。前面的 XML 代码片段包含所需的相关行
引用aop schema 中,以便aop namespace 可用
给你。 |
这jdbc
图式
这jdbc
元素允许您快速配置嵌入式数据库或初始化
现有数据源。这些元素分别记录在 Embedded Database Support 和 Initializing a DataSource 中。
要使用jdbc
schema 中,您需要在
top 的 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 Namespace。 |
2 | 指定位置(包含其他架构位置)。 |