跳到主要内容

附录

ChatGPT-4o-mini 中英对照 Appendix

XML 架构

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

tx 模式

tx 标签用于配置 Spring 对事务的全面支持中的所有 bean。这些标签在名为 Transaction Management 的章节中进行了介绍。

提示

我们强烈建议您查看随 Spring 发行版一起提供的 'spring-tx.xsd' 文件。该文件包含 Spring 事务配置的 XML Schema,并涵盖 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 definitions here -->

</beans>
xml
  • 声明使用 tx 命名空间。

  • 指定位置(与其他模式位置一起)。

备注

通常,当您使用 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 definitions here -->

</beans>
xml
  • 声明使用 jdbc 命名空间。

  • 指定位置(与其他模式位置一起)。