Spring事务管理
来源:互联网 发布:股票佣金万2怎么算法 编辑:程序博客网 时间:2024/04/28 12:39
MySQL事务
请参阅http://blog.csdn.net/keysilence1/article/details/52460851事务篇
Spring事务管理
使用场景
应用于要求数据一致性要求比较高的场合,例如出现异常的情况,不会导致数据不一致,或出现脏数据等。
特点
为多种持久化层API的支持,比如说比较常用的JDBC、Hibernate、JPA、JTA等;
事务管理方式
支持两种:
- 编程式事务管理;
- TransactionTemplate,比较常用的方式;
- PlatformTransactionManager;
- 声明式事务管理;
声明式管理建立在AOP之上,本质上就是在方法前后进行拦截,在目标方法开始之前创建或加入一个事务,在目标方法执行完毕后执行提交或者回滚事务的操作。声明式事务管理最大的优点在于减少对业务的侵入性。- 注:两者之间比较,编程式事务管理可以作用于某一代码块,而声明式事务只能作用于某一方法上。并且对于后者这种管理方式,默认情况下,只有来自外部的调用才会被AOP截获,类内部方法调用本类其他的方法不会引起事务的行为,即使调用方法使用@Transaction注解进行了修饰。
自动提交
Spring底层已经将连接的自动提交属性设置成了false;
代理方式
配置
<context:property-placeholder order="21" location="classpath*:META-INF/spring/jdbc.properties" file-encoding="UTF-8" ignore-unresolvable="true"/><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="user" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> <property name="jdbcUrl" value="${jdbc.url}"/> <property name="driverClass" value="${jdbc.driverClassName}"/> <property name="acquireIncrement" value="${c3p0.acquireIncrement}"/> <property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTestPeriod}"/> <property name="initialPoolSize" value="${c3p0.initialPoolSize}"/> <property name="maxIdleTime" value="${c3p0.maxIdleTime}"/> <property name="maxPoolSize" value="${c3p0.maxPoolSize}"/> <property name="minPoolSize" value="${c3p0.minPoolSize}"/></bean><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /></bean><!-- enable autowire --><context:annotation-config/><!-- 此处使用CGLIB动态代理的方式,默认为JDK动态代理(proxy) --><tx:annotation-driven mode="aspectj" transaction-manager="transactionManager" />
0 0
- 事务管理之Spring事务管理
- Spring事务管理
- spring事务管理
- Spring事务管理
- Spring事务管理
- Spring事务管理
- Spring事务管理
- Spring事务管理
- Spring 事务管理
- Spring事务管理
- spring 事务管理
- spring 事务管理
- spring 事务管理
- spring事务管理
- Spring 事务管理
- Spring事务管理
- spring事务管理
- spring 事务管理
- 《凤凰项目 一个IT运维的故事传奇》读后感
- Hibernate5.2
- 高峰论坛:高级招聘面试技巧(广州站)
- [内核编程] VS2013 WDK8.1 开发,调试驱动(xp win7 亲测)
- VMware+Windbg+Win7 内核驱动调试 ----(环境搭建)
- Spring事务管理
- win系统下无法ping通linux,或是linux无法ping通win系统
- 桥接模式——多层分支也不怕
- sql:ORA-00979:不是GROUP BY 表达式
- java基础_day01
- Struts2 2.5.2的套路
- uva 10327 相邻数字交换排序法
- 不确定性学习(2)
- 解决ng-repeat无法直接显示API返回的url图片