附录
XML模式
本附录的这一部分列出了数据访问的XML模式,包括以下内容:
tx Schema
tx 标签用于配置 Spring 在事务支持方面的所有相关功能。这些标签在名为 事务管理 的章节中有详细介绍。
提示
我们强烈建议您查看随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>
声明使用
tx命名空间。指定位置(与其他模式位置一起)。
备注
通常,当您使用tx命名空间中的元素时,也会同时使用aop命名空间中的元素(因为Spring中的声明式事务支持是通过AOP实现的)。前面的XML片段包含了引用aop模式所需的相关行,这样aop命名空间中的元素才能被您使用。
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>
声明使用
jdbc命名空间。指定位置(与其他模式位置一起)。