Spring的声明式事务
1.与hibernate集成
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml"> </property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory"><ref bean="sessionFactory" /></property>
</bean>
<!--支持@Transactional标记-->
<tx:annotation-driven />
<!-- 支持@AspectJ标记-->
<aop:aspectj-autoproxy />
<!--以AspectJ方式定义AOP -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="find*" read-only="true" />
<tx:method name="search*" read-only="true" />
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<!--以AspectJ方式定义AOP 第二种方法-->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config proxy-target-class="true">
<aop:advisor
pointcut="execution(* com.ssh.idao.*DAO.*(..))"
advice-ref="txAdvice" />
</aop:config>
<bean name="/view" class="com.ssh.struts.action.ViewAction"> </bean>
2.与ibaitis集成,只需配置jdbc事务即可
<context:component-scan base-package="com.filmdubbing.manager"/>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="initialSize" value="5" />
<property name="maxActive" value="100" />
<property name="maxIdle" value="30" />
<property name="maxWait" value="1000" />
<property name="poolPreparedStatements" value="true" />
<property name="defaultAutoCommit" value="true" />
<property name="validationQuery" value="select 1 from dual" />
<property name="testOnBorrow" value="true" />
</bean>
<bean id="yzfwTM" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<tx:advice id="yzfwTA" transaction-manager="yzfwTM">
<tx:attributes>
<tx:method name="get*" propagation="REQUIRED" read-only="true" rollback-for="Throwable" />
<tx:method name="find*" propagation="REQUIRED" read-only="true" rollback-for="Throwable" />
<tx:method name="*" propagation="REQUIRED" rollback-for="Throwable" />
</tx:attributes>
</tx:advice>
<aop:config proxy-target-class="true">
<aop:pointcut id="yzfwTO" expression="execution(* com.filmdubbing.manager..*.*(..))" />
<aop:advisor advice-ref="yzfwTA" pointcut-ref="yzfwTO" />
</aop:config>
Spring的声明式事务的更多相关文章
- spring aop 声明式事务管理
一.声明式事务管理的概括 声明式事务(declarative transaction management)是Spring提供的对程序事务管理的方式之一. Spring的声明式事务顾名思义就是采用声明 ...
- Spring之声明式事务
在讲声明式事务之前,先回顾一下基本的编程式事务 编程式事务: //1.获取Connection对象 Connection conn = JDBCUtils.getConnection(); try { ...
- 【Spring】——声明式事务配置详解
项目中用到了spring的事务: @Transactional(rollbackFor = Exception.class, transactionManager = "zebraTrans ...
- Spring AOP声明式事务异常回滚(转)
转:http://hi.baidu.com/iduany/item/20f8f8ed24e1dec5bbf37df7 Spring AOP声明式事务异常回滚 近日测试用例,发现这样一个现象:在业务代码 ...
- @Transactional、Spring的声明式事务
传送门 一.Spring的声明式事务 需要在xml文件中配置 <!--配置事务管理器类--> <bean id="transactionManager" clas ...
- 使用注解实现Spring的声明式事务管理
使用注解实现Spring的声明式事务管理,更加简单! 步骤: 1) 必须引入Aop相关的jar文件 2) bean.xml中指定注解方式实现声明式事务管理以及应用的事务管理器类 3)在需要添加事务控制 ...
- Spring(四)Spring JdbcTemplate&声明式事务
JdbcTemplate基本使用 01-JdbcTemplate基本使用-概述(了解) JdbcTemplate是spring框架中提供的一个对象,是对原始繁琐的Jdbc API对象的简单封装.spr ...
- 保护亿万数据安全,Spring有“声明式事务”绝招
摘要:点外卖时,你只需考虑如何拼单:选择出行时,你只用想好目的地:手机支付时,你只需要保证余额充足.但你不知道这些智能的背后,是数以亿计的强大数据的支持,这就是数据库的力量.那么庞大数据的背后一定会牵 ...
- spring+springMVC,声明式事务失效,原因以及解决办法
http://blog.csdn.net/z69183787/article/details/37819627#comments 一.声明式事务配置: <bean id="transa ...
- spring的声明式事务,及redis事务。
Redis的事务功能详解 http://ghoulich.xninja.org/2016/10/12/how-to-use-transaction-in-redis/ MULTI.EXEC.DISCA ...
随机推荐
- HDU 1166 敌兵布阵【分块】
Problem Description C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任 ...
- 【SPOJ687&POJ3693】Maximum repetition substring(后缀数组)
题意: n<=1e5 思路: From http://hzwer.com/6152.html 往后匹配多远 r 用ST表求lcp即可...往前 l 就把串反过来再做一下.. 但是有可能求出来的最 ...
- 【Vijos1412】多人背包(背包DP)
题意:求0/1背包的前K优解总和 k<=50 v<=5000 n<=200 思路:日常刷水 归并即可,不用排序 ; ..,..,..]of longint; w,c,a,b:..]o ...
- Codeforces737E. Tanya is 5!
$n \leq 40$个人玩$m \leq 10$台游戏机,每台游戏机一秒内只能一人玩,每人一秒内只能玩一台.每台游戏机有个价格,在规定总价格内可以把一部分游戏机复制一次,每台只能复制一次.给每个人对 ...
- Python入门---易错已错易混淆----知识点
1.not 1 or 0 and 1 or 3 and 4 or 5 and 6 or 7 and 8 and 9 结果会输出啥? 根据优先级:(not 1) or (0 and 1) or (3 a ...
- go1.11新特性,mark一下
包管理新特性: export GO111MODULE=on #开启modules go mod init # 创建go.mod (我是在项目根目录下输入的命令) ls // 可以看下创建成功 cat ...
- linux top %VSZ含义
https://blog.csdn.net/sinohenu/article/details/58216013 https://unix.stackexchange.com/questions/449 ...
- dbms_metadata.get_ddl的使用总结
https://blog.csdn.net/newhappy2008/article/details/34823339
- Peter Norvig:十年学会编程
为啥都想速成? 随便逛一下书店,你会看到<7天自学Java>等诸如此类的N天甚至N小时学习Visual Basic.Windows.Internet的书.我用亚马逊网站的搜索功能,出版年份 ...
- OSI模型详解
OSI 七层模型通过七个层次化的结构模型使不同的系统不同的网络之间实现可靠的通讯,因此其最主要的功能就是帮助不同类型的主机实现数据传输 . 完成中继功能的节点通常称为中继系统.在OSI七层模型中,处于 ...