1.与hibernate集成
<bean id="sessionFactory"   class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:hibernate.cfg.xml"> </property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"><ref bean="sessionFactory" /></property>
</bean> <!--支持@Transactional标记-->
<tx:annotation-driven />
<!-- 支持@AspectJ标记-->
<aop:aspectj-autoproxy />
<!--以AspectJ方式定义AOP -->
<tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="get*" read-only="true" /> <tx:method name="find*" read-only="true" /> <tx:method name="search*" read-only="true" /> <tx:method name="*" /> </tx:attributes>
</tx:advice>

<!--以AspectJ方式定义AOP 第二种方法-->

<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>

<aop:config proxy-target-class="true"> <aop:advisor pointcut="execution(* com.ssh.idao.*DAO.*(..))" advice-ref="txAdvice" />
</aop:config>
<bean name="/view" class="com.ssh.struts.action.ViewAction"> </bean>
2.与ibaitis集成,只需配置jdbc事务即可<context:component-scan base-package="com.filmdubbing.manager"/>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"destroy-method="close"><property name="driverClassName" value="${jdbc.driverClassName}" /><property name="url" value="${jdbc.url}" /><property name="username" value="${jdbc.username}" /><property name="password" value="${jdbc.password}" /><property name="initialSize" value="5" /><property name="maxActive" value="100" /><property name="maxIdle" value="30" /><property name="maxWait" value="1000" /><property name="poolPreparedStatements" value="true" /><property name="defaultAutoCommit" value="true" /><property name="validationQuery" value="select 1 from dual" /><property name="testOnBorrow" value="true" />
</bean>
<bean id="yzfwTM"  class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource" />
</bean>
<tx:advice id="yzfwTA" transaction-manager="yzfwTM"><tx:attributes><tx:method name="get*" propagation="REQUIRED" read-only="true" rollback-for="Throwable" /><tx:method name="find*" propagation="REQUIRED" read-only="true" rollback-for="Throwable" /><tx:method name="*" propagation="REQUIRED" rollback-for="Throwable" /></tx:attributes>
</tx:advice>
<aop:config proxy-target-class="true"><aop:pointcut id="yzfwTO" expression="execution(* com.filmdubbing.manager..*.*(..))" /><aop:advisor advice-ref="yzfwTA" pointcut-ref="yzfwTO" />
</aop:config>

转载于:https://www.cnblogs.com/xunianchong/p/4921177.html

Spring的声明式事务相关推荐

  1. 【SSM框架系列】Spring - JdbcTemplate声明式事务

    JdbcTemplate概述 以往使用jdbc时,每次都需要自己获取PreparedStatement,执行sql语句,关闭连接等操作.操作麻烦冗余,影响编码的效率. Spring把对数据库的操作在j ...

  2. spring配置c3p0连接池、spring的声明式事务管理

    一.spring配置c3p0连接池: 1.导入maven依赖: <!-- https://mvnrepository.com/artifact/com.mchange/c3p0 --> & ...

  3. Spring框架声明式事务管理

    Spring框架声明式事务管理 底层就是AOP原理,面向切面编程 在不修改源码的情况下,对方法进行增强 Spring框架事务管理相关类和API PlatformTransactionManager 平 ...

  4. 保护亿万数据安全,Spring有“声明式事务”绝招

    摘要:点外卖时,你只需考虑如何拼单:选择出行时,你只用想好目的地:手机支付时,你只需要保证余额充足.但你不知道这些智能的背后,是数以亿计的强大数据的支持,这就是数据库的力量.那么庞大数据的背后一定会牵 ...

  5. ❤️Spring的声明式事务

    ❤️Spring的声明式事务 事务在项目开发过程非常重要,涉及到数据的一致性的问题,不容马虎! 事务管理是企业级应用程序开发中必备技术,用来确保数据的完整性和一致性. 事务就是把一系列的动作当成一个独 ...

  6. (续)SSM整合之spring笔记(声明式事务)(P110-116)

    目录 一 .声明式事务概念 二 .基于注解的声明式事务 1 .准备工作 (1)加入依赖 (2)创建jdbc.properties (3)配置Spring的配置文件     tx-annotation. ...

  7. 06_02_任务三:Spring JDBCTemplate 声明式事务

    任务三:Spring JDBCTemplate & 声明式事务 课程任务主要内容: Spring的JdbcTemplate Spring的事务 Spring集成web环境 一 Spring的J ...

  8. Spring的声明式事务底层原理

    文章目录 声明式事务的概述 声明式事务的初探 声明式事务的源码分析 声明式事务的概述 Spring 的声明式事务管理在底层是建立在 AOP 的基础之上的.其本质是对方法前后进行拦截,然后在目标方法开始 ...

  9. Spring AOP声明式事务

    Spring AOP声明式事务 Spring AOP声明式事务 传统spring配置 SpringBoot配置 Spring AOP声明式事务 Spring AOP声明式事务可以帮我们自动管理事务,在 ...

  10. Spring系列--声明式事务管理

    Spring事务管理概述 Spring的事务管理简化了传统的事务管理流程,并且在一定程序上减少了开发者的工作量. 事务管理的核心接口 在Spring的所有JAR包中包含一个名为Spring-tx-5. ...

最新文章

  1. R语言使用timeROC包计算存在竞争情况下的生存资料多个标记物在相同时间下的cox及协变量分析AUC值、并可视化多个标记物在相同时间下的ROC值、多指标的ROC曲线(Time-dependent R
  2. RHEL/CentOS下的VLAN设置
  3. linux忘记root密码怎么办
  4. ecshop订单打印页显示商品缩略图和序号
  5. 恢复Win10照片查看器
  6. linux终端进程bash,让Linux的进程不受终端影响
  7. postgresql 数据表【转】
  8. 【bug解决方案】powershell 中无法激活 conda 环境 /Anaconda 使用 powershell 无效
  9. 微信小程序-强制手机端更新
  10. Element源码系列——搭建Karma测试环境及Eslint语法检测
  11. c语言 除法优化,【小课堂】汇编级除法优化
  12. 互联网晚报 | 06月14日 星期二 | 罗永浩称苹果有些产品明显退步;​旷视首席科学家孙剑博士去世;吉利拟收购魅族...
  13. 手机浏览器播放mp3等音乐(chrome特殊)
  14. Java证书keystore生成过程
  15. Linux驱动的地址空间和硬件地址空间说明——摘自华清远见嵌入式园地 .
  16. ARM/计算机体系结构
  17. python画圆角矩形_js绘制圆角矩形
  18. 在线小蝌蚪匿名聊天室源码 用于网站引流
  19. 打开PDF文件需要使用什么软件?看完你就明白了
  20. Python总纲路线

热门文章

  1. android定位地点的保存,Android获得所有存储设备位置的最佳方法
  2. excel换行按什么键_电脑黑屏按什么键恢复 电脑黑屏的原因和恢复方法
  3. Flask报错RuntimeError: No application found. Either work inside a view function or push an applicatiio
  4. Unity3D基础29:消息发送
  5. bzoj 1048: [HAOI2007]分割矩阵(记忆化搜索)
  6. bzoj 5029 poj 2528 nyoj 1009: 贴小广告(线段树)
  7. C++multiset集合
  8. java执行cmd命令并获取返回结果字符串
  9. vivado和modelsim联合仿真实现占空比1:15的分频
  10. Apache Camel,Spring Boot 实现文件复制,转移 (转)