【问题标题】:how to configure DispatcherServlet and ContextLoaderListener in order to give way to OpenViewInSessionFilter如何配置 DispatcherServlet 和 ContextLoaderListener 以让位于 OpenViewInSessionFilter
【发布时间】:2012-03-07 21:04:47
【问题描述】:

我的事务管理器在使用 spring 3.0.5 和 hibernate 3.6.1 时遇到了一些问题。 在发现我在stackoverflow 上的帖子中需要OpenViewInSessionFilter 后,我尝试了它,但它仍然无法正常工作,因为我仍然拥有lazyInitializationException

我还在这里发现(由于您的 cmets 和知识,谢谢大家)DispatcherServletContextLoaderListener 都有一个 sessionFactory,而 OpenViewInSessionFilter 实际上使用来自 ContextLoaderListener 的那个。

我还了解到,DispatcherServlet 可以从 ContextLoaderLister 转换为 borrow sessionFactory,但反之则不行。

也就是说,我在实践中发现它非常令人困惑,因为正在开展的项目需要同时正常工作。

我的web.xmlapplication contexts 可在pastie 获得

谁能告诉我如何让OpenViewInSessionFilter 工作? 感谢您阅读本文。

【问题讨论】:

    标签: hibernate jakarta-ee servlets spring-mvc web.xml


    【解决方案1】:

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

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

    【讨论】:

    • 你好,我确实这样做了,但仍然有相同的 L.I.E.真的让我抓狂:(
    猜你喜欢
    • 2012-06-14
    • 2016-09-12
    • 1970-01-01
    • 2012-09-01
    • 2014-10-17
    • 1970-01-01
    • 1970-01-01
    • 2020-03-31
    • 1970-01-01
    相关资源
    最近更新 更多