Spring、Spring事务详解;使用XML配置事务
2016-12-01 00:00
579 查看
@Transactional可以设置以下参数:
Propagation 详解:
![](https://static.oschina.net/uploads/img/201612/01101938_unRQ.jpg)
Isolation详解:
![](https://static.oschina.net/uploads/img/201612/01101938_kN2x.jpg)
使用XML配置事务:
注: 使用注解的方式配置事务,更加的方便,可扩展性更高,推荐使用注解的方式配置事务。
@Transactional(readOnly=false) // 指定事务是否只读的 true/false @Transactional(rollbackFor=Exception.class) //指定在什么异常情况下回滚事务,默认在运行时异常回滚(RuntimeException),Exception异常不回滚 @Transactional(noRollbackFor=Exception.class) //指定在什么异常情况下不回滚事务 ,默认在运行时异常回滚(RuntimeException),Exception异常不回滚 @Transactional(noRollbackForClassName="Exception") // 同@Transactional(noRollbackFor=Exception.class) @Transactional(rollbackForClassName="Exception") // 同@Transactional(noRollbackFor=Exception.class) @Transactional(timeout=30000) //设置事务超时时间,默认30秒 @Transactional(propagation=Propagation.NOT_SUPPORTED) //不使用事务;propagation设置事务的传播特性,具体看下面 @Transactional(isolation=Isolation.REPEATABLE_READ) //数据库事务隔离级别
Propagation 详解:
![](https://static.oschina.net/uploads/img/201612/01101938_unRQ.jpg)
Isolation详解:
![](https://static.oschina.net/uploads/img/201612/01101938_kN2x.jpg)
使用XML配置事务:
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="get*" propagation="NOT_SUPPORTED" /> <tx:method name="save*" propagation="REQUIRED" rollback-for="Exception"/> <tx:method name="del*" propagation="REQUIRED" rollback-for="Exception" /> <!-- ... --> </tx:attributes> </tx:advice> <!-- 配置参与事务的类 --> <aop:config> <aop:pointcut id="transcationPointcut" expression="execution(* cn.service.impl.*.*(..))"/> <aop:advisor pointcut-ref="transcationPointcut" advice-ref="txAdvice" /> </aop:config>
注: 使用注解的方式配置事务,更加的方便,可扩展性更高,推荐使用注解的方式配置事务。
相关文章推荐
- Spring、Spring事务详解;使用XML配置事务
- Spring、Spring事务详解;使用XML配置事务
- Spring、Spring事务详解;使用XML配置事务
- Spring 事务的配置和使用详解(包括手动对事务的控制部分)
- applicationContext-common.xml 之spring tx:advice 和 aop:config 配置事务属性详解
- applicationContext-common.xml 之spring tx:advice 和 aop:config 配置事务属性详解
- Spring2.5整合Hibernate3.0中使用XML以tx来配置事务管理。
- applicationContext-common.xml 之spring tx:advice 和 aop:config 配置事务属性详解
- spring 事务一致性使用xml配置
- 详解Spring中使用xml配置bean的细节
- Spring中使用DataSourceTransactionManager进行事务管理的xml配置
- Spring视频学习(十)使用XML配置事务
- applicationContext-common.xml 之spring tx:advice 和 aop:config 配置事务属性详解
- Spring 采用基于XML方式配置事务
- Spring事务配置详解
- spring配置文件application.xml中的事务总结
- Spring 声明式事务管理 Annotation配置 xml文件
- 详解Spring的applicationContext.xml配置文件
- 使用Spring注解方式管理事务与传播行为详解
- Spring事务配置详解