基于tx:aop空间配置的事务管理

该文章是以基于<aop:advisor>方法面向方面编程为基础的,有关详细内容,请看

   http://blog.csdn.net/yi16881/archive/2010/06/09/5659704.aspx

 

本文讲解xml文档中tx:aop配置方法

 

<?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: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/schema/beans/spring-beans-2.5.xsd
 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

//阴影部分配置一定不能忘记,否则不能识别aop和tx

<bean id="datasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName">
            <value>oracle.jdbc.OracleDriver</value>
        </property>
        <property name="url">
            <value>jdbc:oracle:thin:@localhost:1521:orcl</value>
        </property>
        <property name="username">
            <value>system</value>
        </property>
        <property name="password">
            <value>abcd</value>
        </property>
</bean>

//该部分为数据源配置,不再多讲
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="datasource"/>
</bean>

//增加事物管理类DataSourceTransactionManager.class
<aop:config>
<aop:pointcut id="serviceMethod" expression="execution(* insertData(..))"/>
<aop:advisor pointcut-ref="serviceMethod" advice-ref="txAdvice"/>
</aop:config>

//aop部分在该文中开头部分的链接中有详解


<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="insertData"/>
</tx:attributes>
</tx:advice>

//tx:method元素属性如下表
<bean id="testDao" class="com.sias.TestDao">
<constructor-arg><ref local="datasource"/></constructor-arg>
</bean>

</beans>

tx:method属性如下表

事务属性是否必须默认值描述
name与事物相关联的方法,可以用通配符“*”ru get* handler
propagationREQUIRED

事务传播行为,可选值为:

required,supports,mandatory,

requires_new,not_supported,

never,nested

isolationDEFAULT

事务隔离级别,可选值为

default,read_uncommitted,read_committed,

repeatable_read,serializable

timeout-1

事务超时的时间(以秒为单位),如果设置为-1,

事务超时的时间由底层的事物系统决定

read-onlyfalse事务是否只读
rollback-for所有运行期异常回滚

触发事务回滚的Exception,可以设置多个,以

都好分开,如:"Exception1,Exception2"

no-rollback-for所有检查异常不回滚

不触发事务回滚的Exception,可以设置多个,以

逗号分开,如:"Excepition1,Exception2"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值