`
zhougaoyun
  • 浏览: 8304 次
  • 性别: Icon_minigender_1
  • 来自: 厦门
社区版块
存档分类
最新评论

用spring的事务代理解决事务提交问题

    博客分类:
  • SSH2
阅读更多
spring事务提理解决事务提交问题有三种方法,这边是提供的是三种方法中的最佳方法:
1)、在dao类中加入事务标注
import org.springframework.transaction.annotation.Transactional;
2)、在applicationContext.xml配置文件中改变成如下:
<?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-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
">
<tx:annotation-driven transaction-manager="transactionManager"
proxy-target-class="true"/>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean
">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<bean id="StudentDAO" class="dao.StudentDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- 声明一个 Hibernate 3 的事务管理器供代理类自动管理事务用 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionMan
ager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>

</beans>

其中红色部分是需要加入
通过这两个步骤就可以实现spring的事务代理解决事务提交问题
分享到:
评论

相关推荐

    深入理解Spring声明式事务:源码分析与应用实践

    此外,Spring事务管理器支持多种类型的事务策略,包括不同的传播行为和隔离级别,允许开发者根据具体业务场景选择最合适的事务管理策略。深入理解Spring声明式事务的工作原理,不仅能帮助开发者更高效地使用Spring...

    Spring.html

    readuncommited:读未提交,不可以解决任何问题 readcommited:读已提交,可以解决脏读问题 repeatableRead:可重复读,可以解决脏读,不可重复读问题 Serializbler:串行化,可以解决所有问题 超时时间: 默认-1...

    spring in action英文版

     5.6.2 自动代理事务  5.7 小结  第6章 远程调用  6.1 Spring远程调用概览  6.2 与RMI一起工作  6.2.1 连接RMI服务  6.2.2 输出RMI服务  6.3 使用Hessian和Burlap的远程调用  6.3.1 访问...

    spring培训笔记

    spring基础 知识要点: Spring的事务管理及实现,Spring操作Hibernate的事务管理器; 回顾上次课的要点: 代理模式,AOP框架,Spring中AOP的实现方式 ...Durability: 成功提交的事务的持久性. 可掉电保存.

    Spring in Action(第2版)中文版

    6.4.2代理事务 6.4.3在spring2.0里声明事务 6.4.4定义注释驱动事务 6.5小结 第7章保护spring 7.1springsecurity介绍 7.2验证用户身份 7.2.1配置providermanager 7.2.2根据数据库验证身份 7.2.3根据ldap仓库...

    【分布式事务----LCN】LCN原理及使用方式.docx

    当本地事务提交回滚或者关闭连接时将会执行假操作,该代理的连接将由LCN连接池管理。 该模式的特点: - 该模式对代码的嵌入性为低。 - 该模式仅限于本地存在连接对象且可通过连接对象控制事务的模块。 - 该模式下...

    Spring in Action(第二版 中文高清版).part2

    6.4.2 代理事务 6.4.3 在Spring 2.0里声明事务 6.4.4 定义注释驱动事务 6.5 小结 第7章 保护Spring 7.1 Spring Security介绍 7.2 验证用户身份 7.2.1 配置Provider Manager 7.2.2 根据数据库验证身份 ...

    Spring in Action(第二版 中文高清版).part1

    6.4.2 代理事务 6.4.3 在Spring 2.0里声明事务 6.4.4 定义注释驱动事务 6.5 小结 第7章 保护Spring 7.1 Spring Security介绍 7.2 验证用户身份 7.2.1 配置Provider Manager 7.2.2 根据数据库验证身份 ...

    MyEclipse 6 Java 开发中文教程第十章

    225 &lt;br&gt;10.5.2.3 用Spring 1.2 的事务代理类解决事务提交问题... 232 &lt;br&gt;10.5.2.4 用Spring 2.0 的aop和tx声明式配置解决事务提交问题... 234 &lt;br&gt;10.5.2.5 用Spring 2.0 的@Transactional标注解决事务...

    Spring_doc

    Spring的事务管理通过AOP代理来实现 根据事务属性,对每个代理对象的每个方法进行拦截, 在方法执行前启动事务, 方法执行完毕后根据是否有异常和异常种类进行... spring 默认通过捕获运行时异常实现事务提交或回滚

    spring applicationContext 配置文件

    -- 配置要拦截的url,防止2次提交或做其他數據統計用 &lt;bean id="doubleSubmitInterceptor" class="com.ccc.filter.DoubleSubmitInterceptor"&gt; &lt;property name="mappingURL" value=".html" /&gt; ...

    ssh(structs,spring,hibernate)框架中的上传下载

     以上是Spring+Hibernate将文件二进制数据持久化到数据库的解决方案,而Struts通过将表单中file类型的组件映射为ActionForm中类型为org.apache.struts.upload. FormFile的属性来获取表单提交的文件数据。  工程...

    springboot参考指南

    解决自动配置问题 ii. 62.2. 启动前自定义Environment或ApplicationContext iii. 62.3. 构建ApplicationContext层次结构(添加父或根上下文 iv. 62.4. 创建一个非web(non-web)应用 ii. 63. 属性&配置 i. 63.1. ...

    《MyEclipse 6 Java 开发中文教程》前10章

    10.5.2.3 用Spring 1.2 的事务代理类解决事务提交问题 245 10.5.2.4 用Spring 2.0 的aop和tx声明式配置解决事务提交问题 247 10.5.2.5 用Spring 2.0 的@Transactional标注解决事务提交问题(最佳方案) 251 10.5.2.6...

    JAVA高并发高性能高可用高扩展架构视频教程

    spring事务处理 课程文档 高并发之基础数据MySql调优 mongodb 三级联动课程资料 应用架构之灵魂设计模式 应用架构之魂设计模式实战演练应用架构之魂设计模式实战演练 揭开springAOP神秘面纱(动态代理) Mysql性能优化...

    java面试题

    spring使用AOP面向切面的思想进行事务管理的。 spring和Hibernate继承后,定义事务管理特性的时候查询为什么要定义为read-only? 答:因为添加、删除和更新都涉及到了数据库的修改,而查询并未涉及到数据库修改,...

    asp.net知识库

    SubmitOncePage:解决刷新页面造成的数据重复提交问题 SharpRewriter:javascript + xml技术利用#实现url重定向 采用XHTML和CSS设计可重用可换肤的WEB站点 asp.net的网址重定向方法的比较:面向搜索引擎友好 也谈 ...

Global site tag (gtag.js) - Google Analytics