spring事务管理太厉害了!!可以不再自管事务开发了!

spring aop声明式事务配置 问题:
困扰我近十多天的的spring事务管理终于解决了,
再也不用自己管理事务了
嗯,可以删该死的hibernate事务管理代码了
分享一下
配置spring aop声明式事务配置 访问action时hibernate报错
*********is not valid without active transaction

这里星号是某个类
的某有事务体现方法

我曾经尝试了配置4次spring-aop声明式事务,每次都是好几个小时,每次最终我都放弃了,现在问题解决了,
我才发现,其实我离配置成功只差一步:就是
在hibernate.cfg.xml
对hibernate框架的有一句配置:
的会话工厂声明的配置

 <property name="hibernate.current_session_context_class">thread</property>

当然,这在这里是一个错误示范。单独使用hibernate,是正确的

但如果你想整合spring与hibernate的话,就必须改变他

不然就报以上错误。

正确格式(hibernate5):

 <property name="hibernate.current_session_context_class">org.springframework.orm.hibernate5.SpringSessionContext</property>

原因是:
两者会话工厂的,一开始没整合,只有hibernate自然,使用原生配置是没有问题的,
但是一旦与spring框架整合就会有不少问题,
因为这样整合,其实实际上仍然是hibernate再管理事务,spring也只是帮助注入了会话工厂的bean罢了。并没有
发挥出她的事务管理特性,那太可惜了
因为你仍然要自己使用hibernate管理事务。
但改了会话去路.current_session_context_class为 : org.springframework.orm.hibernate5.SpringSessionContext就将会话工厂完完全全交给spring了
千万记住,这是一个大坑,只在spring里配置的话也要注意这个属性

这样就好了,当然,也有可能在你的application.xml有其它基础配置错误,那么我再给出springaop的具体配置hibernate的过程

application.xml

注意导入相应spring包,如tx,aop等
aop包:aspectj系列切面必需包,,aop包依赖aspectj

大局的话采用一个bean一个代理会话的配置

<!--   头缺beans且注意导入相应spring包--->
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.5.xsd">
<!-- 注入会话工厂 我使用的是配置文件导入会话工厂 --><!-- HibernateDaoSupport对dao支持类继承 --><bean id="SessionFactory"class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"><property name="configLocation"value="classpath:hibernate.cfg.xml" /></bean>
<!-- spring-aop --><!-- 定义事务管理器 -->    <bean id="transactionManager"  class="org.springframework.orm.hibernate5.HibernateTransactionManager">  <property name="sessionFactory" ref="SessionFactory" />  </bean>  <!-- 定义事务 -->  <tx:advice id="txAdvice" transaction-manager="transactionManager">  <tx:attributes>  <tx:method name="select*" propagation="REQUIRED" />  </tx:attributes>  </tx:advice>  <!-- 定义切面 -->  <aop:config>  <aop:pointcut id="PointCuts" expression="execution(* com.j.daoimpl.*.*(..))" />  <aop:advisor advice-ref="txAdvice" pointcut-ref="PointCuts" />  </aop:config>

配置完毕!!!

再来一波,spring真是好框架!

感谢博主maoyuanming0806,他的博文让我对spring配置的流程更少的盲点,一语惊醒梦中人!!!
并给出原文链接:

https://blog.csdn.net/maoyuanming0806/article/details/61417995

总结xml配置spring-aop声明式事务配置与hibernate报错:** isno active spring和hibernate整合,原因会话工厂去路(到spring不仅仅是bean)错误相关推荐

  1. Spring AOP声明式事务

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

  2. 【Spring】——声明式事务配置详解

    事务管理是企业级应用程序开发中必备技术,用来确保数据的完整性和一致性.本文主要讲解事务涉及到一些概念以及spring中事务的使用.如有理解偏颇之处,恳请各位大神指正,小编不胜感激! 1.何为事务? 事 ...

  3. spring aop 声明式事务管理

    http://www.cnblogs.com/wangkaipeng/p/5782116.html

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

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

  5. Spring声明式事务配置详解

    事务管理是企业级应用程序开发中必备技术,用来确保数据的完整性和一致性.本文主要讲解事务涉及到一些概念以及spring中事务的使用.如有理解偏颇之处,恳请各位大神指正,小编不胜感激! 1.何为事务?   ...

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

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

  7. AspectJ声明式事务配置

    2019独角兽企业重金招聘Python工程师标准>>> Spring声明式事务配置,实现模拟转账过程 (AspectJ) 编程式事务要修改service层的代码,很少用,相比之下,A ...

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

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

  9. ❤️Spring的声明式事务

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

最新文章

  1. 业界 | 德勤预测:机器学习走向移动端成大势所趋,或将再掀行业新浪潮
  2. 【若依(ruoyi)】打印bootstrapTable数据
  3. C++校招常见面试题(2019年校招总结)
  4. linux运行中望cad,国产CAD软件中望的Linux版适配UOS, 我在国产系统里试了试
  5. mysql删除字段的方法总结
  6. [USACO10MAR]伟大的奶牛聚集
  7. web_MDN学习资源导航_js初学者快速入门指南项目/javascript高级程序设计vsMDN javascript教程/指南(official)
  8. Linux ---- 安装虚拟机
  9. python基础教程十进制_Python基础教程(四)
  10. matlab许可证_MATLAB校园许可证更新指南
  11. 【HEOI2013】bzoj3168 钙铁锌硒维生素
  12. 没想到这一天来的这么快 大数据之下再无隐私
  13. 关于睡眠你应该知道的十件事
  14. html获取问号后的参数,html问号后的值怎么获取
  15. pytorch指定GPU训练
  16. 【翻译】CEDEC2014跨世代多平台并行开发PS4版如龙维新开发的一年
  17. switzerland, we're coming
  18. 【学习笔记】pytorch迁移学习-猫狗分类实战
  19. 【Java】高并发-JUC:JUC中的Condition对象
  20. wincc工程组态论文_VBA技术在WinCC工程组态中的应用.pdf

热门文章

  1. XAML 布局StackPanel
  2. 关于Unity实现AR功能(四)设置相机的对焦
  3. exists改写SQL,使其走正确的执行计划
  4. oracle 数据库的非指令备份方法
  5. iOS之自定义封装tabBar
  6. 并发编程——进程——理论知识
  7. 2016年第七届蓝桥杯C/C++ B组国赛 —— 第三题:棋子换位
  8. Exp4 恶意代码分析 20164309
  9. 【STM32】低功耗相关函数和类型
  10. 【ARM】Programmers Model