附錄

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 definitions here -->

</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 definitions here -->

</beans>
1 宣告使用 jdbc 名稱空間。
2 指定位置(與其他模式位置一起)。
© . This site is unofficial and not affiliated with VMware.