附錄
XML Schema
附錄的這部分列出資料存取的 XML Schema,包括以下內容
tx
Schema
tx
標籤用於組態 Spring 全面交易支援中的所有 Bean。這些標籤在標題為 交易管理 的章節中涵蓋。
我們強烈建議您查看 Spring 發行版隨附的 'spring-tx.xsd' 檔案。此檔案包含 Spring 交易組態的 XML Schema,並涵蓋 tx 命名空間中的所有各種元素,包括屬性預設值和類似資訊。此檔案已內嵌文件,因此,為了遵守 DRY(Don't Repeat Yourself,不要重複自己)原則,此處不再重複資訊。 |
為了完整起見,若要使用 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 位置)。 |