使用Spring 2.0 新特性实现声明式事务管理-基于XML Schema
来源:互联网 发布:立方米网络规模 编辑:程序博客网 时间:2024/05/16 14:49
在Spring 2.0 中要设置声明式事务管理,可以依赖Spring 2.0 的<aop>与<tx>标签
首先需要设置声明
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework/org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/shcema/beans/spring-beans-2.0./xsd
http://www.springframework.org/scheam/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
</beans>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework/org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/shcema/beans/spring-beans-2.0./xsd
http://www.springframework.org/scheam/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
</beans>
事务是系统层面的服务,也就是一个Aspect,其实具体来说是一个advice,您可以使用<tx:advice>标签来提供这个 advice它需要设置一个TransactionManager,并在当中使用<tx:attributes>来设置事务相关属性
具体应用:
<bean id="dataSource"......></bean>
<bean id="transactionManager" .....></bean>
<bean id="userDAO"....></bean>
<!--
注意到<tx:method>中的属性设置,对于传播行为,隔离层级,只读,超时,异常时撤销或提交,都对应的propagation,
isolation,timeout,read-only,rollback-for,no-rollback-for属性可以设置,若不设置,默认值是REQUIRED,DEFAULT,-1,false
-->
<tx:advice id="txtAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:methpd name="find*" read-only="true"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="userDAOPointCut" expression="execution(* onlyfun.service.IUserDAO.* (..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="userDAOPointCut"/>
</aop:config>
<bean id="transactionManager" .....></bean>
<bean id="userDAO"....></bean>
<!--
注意到<tx:method>中的属性设置,对于传播行为,隔离层级,只读,超时,异常时撤销或提交,都对应的propagation,
isolation,timeout,read-only,rollback-for,no-rollback-for属性可以设置,若不设置,默认值是REQUIRED,DEFAULT,-1,false
-->
<tx:advice id="txtAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:methpd name="find*" read-only="true"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="userDAOPointCut" expression="execution(* onlyfun.service.IUserDAO.* (..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="userDAOPointCut"/>
</aop:config>
- 使用Spring 2.0 新特性实现声明式事务管理-基于XML Schema
- 使用Spring 2.0 新特性实现声明式事务管理-基于XML Schema
- 使用Spring 2.0 新特性实现声明式事务管理-基于Annotation
- Spring声明式事务管理(基于XML方式实现)
- 使用Spring 2.0新特性实现前置通知--基于Schema方式
- spring 声明式事务管理xml方式实现
- spring使用xml进行声明式事务管理
- 使用Spring的XML声明式事务管理
- 使用XML Schema配置spring事务管理
- Spring声明式事务管理(基于xml的方式)
- spring声明式事务管理(基于AspectJ的xml方式)
- Spring 声明式事务管理----基于AspectJ的XML方式
- Spring声明式事务管理之xml事务管理
- 【spring框架】spring使用XML进行声明式事务管理
- Spring声明式事务管理(基于注解方式实现)
- spring中声明式事务管理控制介绍以及使用XML方式实现
- Spring的使用Annotation以及XML进行声明式事务管理
- Spring使用XML进行声明式的事务管理
- Oracle 精妙SQL语句集锦
- 估算数学常量e的值:e=1+1/1!+1/2!+1/3!+...
- Second life的源码销售方式
- C#聊天室
- 最长公共子串及其长度
- 使用Spring 2.0 新特性实现声明式事务管理-基于XML Schema
- 《精通正则表达式》读书笔记摘要: 第一章 入门(2)
- 使用Spring JdbcTemplate实现CLOB和BLOB的存取
- JAR 文件揭密-- 探索JAR 文件格式的强大功能
- error C2143: 语法错误 : 缺少“{”(在“:”的前面)编译错误的解决
- 我不是程序员了,所以离开
- 基于SVG技术实现WebGIS的基本功能
- 崇明一日游
- task_struct结构描述