添加事务管理
来源:互联网 发布:使用数据库 编辑:程序博客网 时间:2024/05/17 16:13
在service层,里面的方法通常是包含一些复杂逻辑的,一个方法可能就调用了dao的多个方法,所以就必须做到事务管理,要么service方法里面的dao方法全部执行,要么全部撤销。这样才能保证数据库数据的正确性。
@Transactional属性
属性 类型 描述
value String 可选的限定描述符,指定使用的事务管理器
propagation enum: Propagation可选的事务传播行为设置
isolation enum: Isolation可选的事务隔离级别设置
readOnly boolean读写或只读事务,默认读写
timeout int (in seconds granularity)事务超时时间设置
rollbackFor Class对象数组,必须继承自Throwable导致事务回滚的异常类数组
rollbackForClassName 类名数组,必须继承自Throwable导致事务回滚的异常类名字数组
noRollbackFor Class对象数组,必须继承自Throwable不会导致事务回滚的异常类数组
noRollbackForClassName 类名数组,必须继承自Throwable不会导致事务回滚的异常类名字数组
配置root-context.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd"
>
<!-- Root Context: defines shared resources visible to all other web components -->
<!-- enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven/>
<!-- a PlatformTransactionManager is still required -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- (this dependency is defined somewhere else) -->
<property name="dataSource" ref="dataSource" />
</bean>
</beans>
@Transactional属性
属性 类型 描述
value String 可选的限定描述符,指定使用的事务管理器
propagation enum: Propagation可选的事务传播行为设置
isolation enum: Isolation可选的事务隔离级别设置
readOnly boolean读写或只读事务,默认读写
timeout int (in seconds granularity)事务超时时间设置
rollbackFor Class对象数组,必须继承自Throwable导致事务回滚的异常类数组
rollbackForClassName 类名数组,必须继承自Throwable导致事务回滚的异常类名字数组
noRollbackFor Class对象数组,必须继承自Throwable不会导致事务回滚的异常类数组
noRollbackForClassName 类名数组,必须继承自Throwable不会导致事务回滚的异常类名字数组
配置root-context.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd"
>
<!-- Root Context: defines shared resources visible to all other web components -->
<!-- enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven/>
<!-- a PlatformTransactionManager is still required -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- (this dependency is defined somewhere else) -->
<property name="dataSource" ref="dataSource" />
</bean>
</beans>
阅读全文
0 0
- 添加事务管理
- spring添加事务管理
- Hibernate事务管理读书笔记(不断添加中)
- 事务管理
- 事务管理
- 事务管理
- 事务管理
- 事务管理
- 事务管理
- 事务管理
- 事务管理
- 事务管理
- 事务管理
- 事务管理
- 事务管理
- 事务管理
- 事务管理
- 事务管理
- FloatingActionButton滚动时的显示与隐藏小结
- 梦想
- 如何使用Eclipse最简单地配置其他语言的IDE环境:例子-Python
- udp和tcp的区别
- 欢迎使用CSDN-markdown编辑器
- 添加事务管理
- TCP和UDP详解
- GOLANG项目:文本排序程序
- Fuel手动安装Mirantis(openstack) 7.0,如何访问FuelWebUI
- js 通过兼容性写法获取样式
- Linux的SOCKET编程详解
- 从零开始写javaweb框架笔记17-搭建轻量级JAVAWEB框架-请求转发
- 【Linux】alias及设置
- 轻量级框架开发