首页 技术 正文
技术 2022年11月15日
0 收藏 945 点赞 3,726 浏览 1764 个字

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>
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,580
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918