Spring学习笔记(四)
来源:互联网 发布:ios11 蜂窝移动网络 编辑:程序博客网 时间:2024/05/16 06:23
1、事务管理配置
配置Sping的声明式事务
①配置事务管理器
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="mySessionFactory"> </property></bean>
②配置事务属性,需要事务管理器
<tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="*" propagation="REQUIRED"/> </tx:attributes></tx:advice>
③配置事务切点, 并把切点和事务属性关联起来
<aop:config> <aop:pointcut expression="execution(* com.service.*.*(..))" id="txPointcut"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/></aop:config>
2、事务传播
required:存在事物则加入,否则新建
required_new:每次都新建事物
supports:有事物则加入,没有以非事务方式执行
not_supported:不支持事物,有事物则暂停该事物,以非事务方式执行
mandatory:必须有事物,当前没有事物则抛出异常
never:不支持事物,当前有事物则抛出异常
nested:嵌套事物,有事物则嵌套,没有则新建。类似数据库save point保存点。必须使用jdbc3协议的驱动,事物管理器必须支持(DateSourceTransactionManager默认支持,HIbernateTransactionManager默认不支持需要设置nestedTransactionAllowed属性为true)
3、开启注解事物管理
<tx:annotation-driven transaction-manager="transactionManager"/> @Transactional(propagation=Propagation.REQUIRED,readOnly=true)
事物注解:方法>类>接口
readOnly = false //读写事务 timeout = -1 //事务的超时时间,-1为无限制 noRollbackFor = ArithmeticException.class //遇到指定的异常不回滚 isolation = Isolation.DEFAULT //事务的隔离级别,此处使用后端数据库的默认隔离级别 propagation = Propagation.REQUIRED //事务的传播行为
阅读全文
0 0
- Spring学习笔记(四)
- Spring学习笔记(四)
- Spring 学习笔记(四)
- Spring学习笔记(四)
- spring学习笔记(四)
- Spring学习笔记(四)
- spring学习笔记四
- spring学习笔记四
- 学习Spring笔记四
- Spring学习笔记(四)----SSH整合
- spring security(四)认证---学习笔记
- Spring学习笔记(四)注入参数
- Spring学习笔记(四)-----AOP
- spring JpetStore学习笔记(四)
- Spring security学习笔记四
- Spring学习笔记(四)Spring配置文件方式实现AOP
- Spring学习笔记(四)-- Spring事务全面分析
- spring笔记(四)
- Linux centos 查看该系统的位数的方法
- 两个栈实现一个队列/两个队列实现一个栈
- Fedora 9下QT4简单编程
- 定时器
- HTML5 WebSocket小小聊天室
- Spring学习笔记(四)
- Linux防火墙配置
- Java用享元模式优化程序性能
- Ubuntu 16.04 apt-get更换为国内阿里云源
- 利用fiddler做mock
- CAD绘图控件VectorDraw web library (javascript)更新至v7.7014.0.2
- 程序设计基础及数据结构基础
- JS变量和数据类型
- poj1703——Find them, Catch them