报错:No Hibernate Session bound to thread的解决办法。

No Hibernate Session bound to thread的解决办法:
在这里插入图片描述

> org.hibernate.HibernateException: **No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here**

今天整合了一下hibernate+spring+spring mvc,在度娘上找了各种办法,还是报到上面这个错误,可能自己错的比较别致吧,总是和标准错误有些偏差,检查了spring的配置文件:

<!-- 开启扫描 -->
	<context:component-scan base-package="studentMS">
	</context:component-scan>

还有spring mvc的配置文件:

<!-- 配置自动扫描的包 -->
	<context:component-scan base-package="studentMS">
		<context:exclude-filter type="annotation"
			expression="org.springframework.stereotype.Service" />
	</context:component-scan>

这两个地方扫描都是没有问题的,解释的话我不多说,后面有空再补上,博客上也已经有大佬讲的很清楚了,可以去参考一下spring和spring mvc 在包扫描上的具体区别。
我这里主要讲我这里报的错:No Hibernate Session bound to thread。
在网上也搜了蛮多解决这个错的方法,都试了下,很不巧的是我这边还是报这个错:No Hibernate Session bound to thread。

这是之前写的:
在这里插入图片描述
这是改了之后的:
在这里插入图片描述
亲测有效

改完之后发现这个错就不报了,可能不适合所有的情况,这个是我这个项目的解决办法,具体的分析后面补上…

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_44810972/article/details/106722511