No Hibernate Session bound to thread, and configuration does not allow create解决方案

参考地址:http://forum.spring.io/forum/spring-projects/data/96622-no-hibernate-session-bound-to-thread-and-configuration-does-not-allow-creation-of-no

1、使用注解实现程序

 dao                           @Repository

service                      @Service        @Transactional

controller                 @Controller     @RequestMapping(value="/")

2、配置Spring 3 + Hibernate 3 (MVC)

启动正常,请求数据库错误,后台报No Hibernate Session bound to thread, and configuration does not allow create错误。

但是事务是配置了的,但是貌似是事务的问题,多方寻求无果,最后在spring网站上找到了解决方案。

3、解决方案在web.xml中加入Hibernate的过滤请求将session打开

<filter>
    <filter-name>openSessionInViewFilter</filter-name>
    <filter-class>
        org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    </filter-class>
</filter>

<filter-mapping>
    <filter-name>openSessionInViewFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
有关OpenSessionInViewFilter的参考http://docs.spring.io/spring/docs/3.0.x/javadoc-api/org/springframework/orm/hibernate3/support/OpenSessionInViewFilter.html

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值