如何配置DispatcherServlet和ContextLoaderListener以让位给OpenViewInSessionFilter [英] how to configure DispatcherServlet and ContextLoaderListener in order to give way to OpenViewInSessionFilter

查看:125
本文介绍了如何配置DispatcherServlet和ContextLoaderListener以让位给OpenViewInSessionFilter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用spring 3.0.5和hibernate 3.6.1的事务管理器中遇到了一些问题。
在发现我需要 OpenViewInSessionFilter stackoverflow 我试过了,它仍然没有工作,因为我还有 lazyInitializationException code>。



我也在这里发现(由于你的意见和知识,谢谢你们), DispatcherServlet ContextLoaderListener 都有一个 sessionFactory ,并且 OpenViewInSessionFilter 实际上使用了一个从 ContextLoaderListener

我也知道 DispatcherServlet can 借用sessionFactory from ContextLoaderLister ,但不是相反。



表示我在实践中发现它很混乱



我的 web.xml 应用程序上下文可在 pastie 上找到



任何人都可以告诉我如何获得 OpenViewInSessionFilter 工作吗?
感谢您阅读本文。

解决方案

您不应该将配置放在web.xml中,只是放在applicationContext中。 XML。下一个viewResolver(我把它放在旁边),包括代码:

 < mvc:interceptors> 
< bean id =openSessionInViewInterceptor
class =org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor>
< property name =sessionFactoryref =sessionFactory/>
< / bean>
< / mvc:interceptors>


I've been have some issues with my transaction manager using spring 3.0.5 and hibernate 3.6.1. After finding out that i needed an OpenViewInSessionFilter in a post on stackoverflow i've tried it and it still wasn't working as i was still having lazyInitializationException.

i've also found here (due to your comments and knowledge, thanks guys) that both DispatcherServlet and ContextLoaderListener have each a sessionFactory and that OpenViewInSessionFilter actually uses the one from ContextLoaderListener.

I've also learnt that DispatcherServlet can borrow sessionFactory from ContextLoaderLister but not the other way round.

that said i found it very confusing in the practice as the kind of project am working on needs both to work properly.

my web.xml and application contexts are available on pastie

Can anyone show me how to get the OpenViewInSessionFilter working? thanks for reading this.

解决方案

You shouldn't put the configuration in web.xml, just in applicationContext.xml. Next of the viewResolver (I put next to it), include the code:

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

这篇关于如何配置DispatcherServlet和ContextLoaderListener以让位给OpenViewInSessionFilter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆