spring+Hibernate5的Could not obtain transaction-synchronized Session for current thread解决
2018-02-05 23:59
766 查看
2018-2-5结合https://www.cnblogs.com/biobio/p/7754080.html http://blog.csdn.net/frankcheng5143/article/details/51308344成功解决问题。前言在整合springmvc4+spring4+hibernate5时,DAO层在getCurrentSession()时报错:Requestprocessing failed; nested exception is org.hibernate.HibernateException: Couldnot obtain transaction-synchronized Session for current thread错误跟踪到sessionFactory.getCurrentSession();protected Session getCurrentSession() { return this.sessionFactory.getCurrentSession();}解决方案原理都在上面两个链接,我也是看的一脸懵逼,不过我直接把方法给出,只需要修改两个文件,也就是applicationContext.xml和springmvc.xml,下面就是我的成功配置。-------------------------------------------------------------------------------可能有些人的@Transactional配置是在dao层,所以要要要把springmvc.xml文件中org.springframework.stereotype.Service和org.springframework.stereotype.Repository都都都不扫描。-------------------------------------------------------------------------------applicationContext.xml(只扫描dao层和Service层)
<!-- 扫描路径,不扫描Controller a1f2 --> <context:component-scan base-package="casic.bj(改为你的包名)"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan>-------------------------------------------------------------------------------springmvc.xml中(只扫描@controller)
<context:component-scan base-package="casic.bj(改为你的包名)"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository" /></context:component-scan>
相关文章推荐
- Spring-hibernate开发时遇到 Could not obtain transaction-synchronized Session for current thread的问题解决
- Could not obtain transaction-synchronized Session for current thread 错误的解决方法!
- Could not obtain transaction-synchronized Session for current thread解决方法
- Could not obtain transaction-synchronized Session for current thread
- HibernateException: Could not obtain transaction-synchronized Session for current thread
- springmvc+spring4+hibernate4整合Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread 报错在spring注解定时任务上的处理
- 错误记录(九)Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- 【Hibernate】Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- 关于Hibernate Could not obtain transaction-synchronized Session for current thread
- Hibernate4 提示Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread原因及解决方案
- 事务配置不对导致:•Could not obtain transaction-synchronized Session for current thread
- SSH整合时出现Could not obtain transaction-synchronized Session for current thread
- 由Could not obtain transaction-synchronized Session for current thread错误处理引申到声明式与编程式事务处理