Spring OpenSessionInViewInterceptor doesn't work

给你一囗甜甜゛ 提交于 2019-11-30 07:32:49

Are you using the @RequestMapping annotation? If I remember right there was an issue with putting the interceptor on the url bean. With Spring 3.0 you can define the interceptor like this:

<mvc:interceptors>
    <bean class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
        <property name="sessionFactory">
            <ref local="sessionFactory" />
        </property>
    </bean>
</mvc:interceptors>

assuming that sessionFactory is a reference to your SessionFactory bean.

You will also need to include the mvc namespace.

xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"

Try using <mvc:interceptors>.

By the way, @Transactional is a different thing - it doesn't make your collections work in the "view". It just opens a transaction (and a session) for the annotated method (and the methods it calls)

If you are using Struts2 with Spring and Hibernate, Try to use OpenSesisonInViewFilter and assign it in web.xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!