附錄
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 位置)。 |