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 ...
随机推荐
- 空指针问题(java.lang.NullPointerException)
在Java中对值为null的指针调用任何方法,就会引发空指针异常(java.lang.NullPointerException).空指针异常绝对是Java中最难查找和调试的一种异常,你永远无法得到任何 ...
- java system.out.printf()的使用方法
package test; public class Main { public static void main(String[] args) { // 定义一些变量,用来格式化输出. double ...
- 怎么用SQL语句查数据库中某一列是否有重复项
SELECT 某一列, COUNT( 某一列 ) FROM 表 GROUP BY 某一列 HAVING COUNT( 某一列 ) 〉1 这样查询出来的结果, 就是 有重复, 而且 重复的数量.
- 发展城市 BZOJ 3700
发展城市 [问题描述] 众所周知,Hzwer学长是一名高富帅,他打算投入巨资发展一些小城市. Hzwer打算在城市中开N个宾馆,由于Hzwer非常壕,所以宾馆必须建在空中,但是这样就必须建立宾馆之间的 ...
- hdu 4965 矩阵快速幂 矩阵相乘性质
Fast Matrix Calculation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Jav ...
- msp430入门学习44
msp430的其他十二 msp430入门学习
- intellij idea springmvc web工程之helloworld
1.新建java工程 2.设置项目 2.添加jar包 3.配置web.xml <?xml version="1.0" encoding="UTF-8"?& ...
- 简单、强大的swig.js
Swig.js A simple, powerful, and extendable JavaScript Template Engine. 简单概括:JS模板引擎. Why to use 根据路劲渲 ...
- MongoDB副本集的原理,搭建
介绍: mongodb副本集即客户端连接到整个副本集,不关心具体哪一台机器是否挂掉.主服务器负责整个副本集的读写,副本集定期同步数据备份,一旦主节点挂掉,副本节点就会选举一个新的主服务器,这一切对于应 ...
- LeetCode_Lowest Common Ancestor of a Binary Search Tree (Binary Tree)
Lowest Common Ancestor of a Binary Search Tree 一.题目描写叙述 二.思路及代码 二叉搜索树有个性质:左子树的值都比根节点小,右子树的值比根节点大.那么我 ...