Spring-tx.xml

配置思路:

1. 声明事务管理器DataSourceTransactionManager,并注入数据源dataSource属性

2.配置事务增强<tx:advice>,声明事务管理器transaction-manager="",默认值为transaction-manager="transactionManager",设置事务属性<tx:attributes>,声明要为哪些方法配置事务<tx:method name=""/>,以及定义方法的一些属性

3. 配置切面<aop:config>,首先通过切入点表达式声明切入点位置,然后关联事务通知和切入点

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean> <!-- 配置事务增强 -->
<tx:advice id="transaction" transaction-manager="transactionManager">
<!-- 事务属性 -->
<tx:attributes>
<tx:method name="*"/>
<tx:method name="get*" read-only="true"/>
<tx:method name="find*" read-only="true"/>
<tx:method name="list*" read-only="true"/> <!--增删改 -->
<tx:method name="insert*" timeout="5000" rollback-for="java.lang.Exception"/>
<tx:method name="add*" timeout="5000"/>
<tx:method name="update*" timeout="5000"/>
<tx:method name="delete*" timeout="5000"/>
</tx:attributes>
</tx:advice> <!-- 配置版的事务切面 -->
<aop:config>
<!-- *任意返回值 impl包下 .*任意类 .*任意方法 (..)任意参数 -->
<aop:pointcut id="pointcut" expression="execution(* com.juyss.service.impl.*.*(..))"/>
<!-- advice-ref:关联增强事务 pointcut-ref:关联事务的切入点 -->
<aop:advisor advice-ref="transaction" pointcut-ref="pointcut"/>
</aop:config> </beans>

最新文章

  1. [spring源码学习]七、IOC源码-Context
  2. 制作简单的2D物理引擎(零)
  3. Windows Server 2016正式版14393英文版ISO镜像下载:_X64FRE_ZH-CN.ISO
  4. Kali Linux渗透基础知识整理(四):维持访问
  5. java中的负数的问题
  6. [FMS]FMS流媒体服务器onStatus介绍说明
  7. Java读数据是的编码问题。
  8. HDU 1014:Uniform Generator
  9. EJB总结
  10. 最新Android 出现Please ensure that adb is correctly located at问题的解决方法
  11. 分析Ext2文件系统结构。
  12. 一步一步在Windows中使用MyCat负载均衡 下篇
  13. JS的DOM操作及动画
  14. Mysql 忘记root密码后修改root密码
  15. hdu 5446(中国剩余+lucas+按位乘)
  16. 介绍一种很棒的wince 如何替换系统声音的方法
  17. Matlab中小语法点总结(更新中)
  18. mysqlsla快速入门
  19. Linux 标准文件描述符
  20. C语言之Bit-wise Operation和Logical Operation

热门文章

  1. 为什么要从 Linux 迁移到 BSD3
  2. 【java框架】MyBatis(7)--MyBatis注解开发
  3. Codeforces Round #548 C. Edgy Trees
  4. Django分页器组建
  5. 2.pandas常用读取
  6. [源码解析] 并行分布式框架 Celery 之架构 (2)
  7. JAVA使用SizeOf
  8. Nacos 2.0 正式发布,性能提升了 10 倍!!
  9. istio in kubernetes (二) -- 部署篇
  10. Hadoop学习笔记—Yarn