<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    kingpub

    海內存知己,博客若比鄰

     

    Hibernate/Spring/Struts架構使用OpenSessionInView的問題


    我原來用struts/spring/hibernate的時候同樣使用OpenSessionInView,但是似乎沒有robbin所說的問題啊。而且我在使用的時候,是ContextLoaderListener和ContextLoaderPlugIn一起用的。整個配置如下:
    1.首先是web.xml
    java代碼:?


    ? ? ? ? <filter>
    ? ? ? ? <filter-name>OpenSessionInViewFilter</filter-name>
    ? ? ? ? <filter-class>org.springframework.orm.hibernate.support.OpenSessionInViewFilter</filter-class>
    ? ? </filter>
    ? ?
    ? ? <filter-mapping>
    ? ? ? ? <filter-name>OpenSessionInViewFilter</filter-name>
    ? ? ? ? <url-pattern>/*</url-pattern>
    ? ? </filter-mapping>
    ? ?
    ? ? <listener>
    ? ? ? ? ? ? ? ? <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    ? ? ? ? </listener>

    ......



    2. 然后是struts-config.xml:
    java代碼:?


    <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
    ? ? ? ? <set-property property="contextConfigLocation"
    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? value="/WEB-INF/action-servlet.xml"
    ? ? ? ? />
    </plug-in>



    其余部分省略。

    在上述配置下,使用OpenSessionInView似乎沒有問題。

    不知道robbin所說的ContextLoaderListener和ContextLoaderPlugIn不應該同時使用是不是做得是如下的配置:(struts-config.xml)

    java代碼:?


    <plug-in
    className="org.springframework.web.struts.ContextLoaderPlugIn">
    <set-property property="contextConfigLocation"
    value="/WEB-INF/applicationContext.xml,
    /WEB-INF/action-servlet.xml"/>
    </plug-in>



    我嘗試了一下,用這種配置時,OpenSessionInView的確失效了。

    我猜想,原因大概是這樣:struts的這個plugIn,可能只是為了整合一個action-servlet.xml,將action-servlet.xml中的定義當作Spring的bean來使用,因此,在保存時,只要有action-servlet.xml的配置,就被保存到robbin所提到的那個attrName中,而不是WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE中,所以,OpenSessionInView是取不到這個配置的。

    那么這個配置什么時候被取到呢?直覺告訴我,可能是和Action的Proxy有關。于是,查看了org.springframework.web.struts.DelegatingActionProxy的源碼,果然:
    java代碼:?


    /**
    ? ? ? ? * Return the delegate Action for the given mapping.
    ? ? ? ? * <p>The default implementation determines a bean name from the
    ? ? ? ? * given ActionMapping and looks up the corresponding bean in the
    ? ? ? ? * WebApplicationContext.
    ? ? ? ? * @param mapping the Struts ActionMapping
    ? ? ? ? * @return the delegate Action
    ? ? ? ? * @throws BeansException if thrown by WebApplicationContext methods
    ? ? ? ? * @see #determineActionBeanName
    ? ? ? ? */

    ? ? ? ? protectedAction getDelegateAction(ActionMapping mapping)throws BeansException {
    ? ? ? ? ? ? ? ? WebApplicationContext wac = getWebApplicationContext(getServlet(), mapping.getModuleConfig());
    ? ? ? ? ? ? ? ? String beanName = determineActionBeanName(mapping);
    ? ? ? ? ? ? ? ? return(Action) wac.getBean(beanName, Action.class);
    ? ? ? ? }

    ? ? ? ? /**
    ? ? ? ? * Fetch ContextLoaderPlugIn's WebApplicationContext from the
    ? ? ? ? * ServletContext, containing the Struts Action beans to delegate to.
    ? ? ? ? * @param actionServlet the associated ActionServlet
    ? ? ? ? * @param moduleConfig the associated ModuleConfig
    ? ? ? ? * @return the WebApplicationContext
    ? ? ? ? * @throws IllegalStateException if no WebApplicationContext could be found
    ? ? ? ? * @see DelegatingActionUtils#getRequiredWebApplicationContext
    ? ? ? ? * @see ContextLoaderPlugIn#SERVLET_CONTEXT_PREFIX
    ? ? ? ? */

    ? ? ? ? protected WebApplicationContext getWebApplicationContext(
    ? ? ? ? ? ? ? ? ? ? ? ? ActionServlet actionServlet, ModuleConfig moduleConfig)throwsIllegalStateException{
    ? ? ? ? ? ? ? ? return DelegatingActionUtils.getRequiredWebApplicationContext(actionServlet, moduleConfig);
    ? ? ? ? }



    仔細看其中的取wac的代碼,它并不是從WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE取的wac。

    由此,我相信,除了robbin講的修改源碼以外,同時使用ContextLoaderListener和ContextLoaderPlugIn,但是不要在ContextLoaderPlugIn里面加入applicationContext.xml,只要加入你的action-servlet.xml,我相信,同樣也可以非常流暢的使用OpenSessionInView

    posted on 2006-06-20 12:40 xiaofeng 閱讀(138) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    導航

    統計

    常用鏈接

    留言簿(2)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    收藏夾

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 羞羞视频免费网站在线看| 亚洲人成网网址在线看| 青青久在线视频免费观看| 午夜爱爱免费视频| 亚洲宅男天堂a在线| 日韩在线观看视频免费| 在线A级毛片无码免费真人| 亚洲精品伊人久久久久| 成人黄色免费网址| 亚洲成人福利在线| 中文字幕无码成人免费视频 | 亚洲日韩精品一区二区三区无码| 国产成人亚洲精品蜜芽影院| 国产免费爽爽视频在线观看| 亚洲大尺度无码专区尤物| 亚洲AV无码一区二区三区久久精品 | 亚洲国产日韩精品| 在线免费观看a级片| 亚洲成a人片在线观看天堂无码| 香蕉高清免费永久在线视频| 男男黄GAY片免费网站WWW| 亚洲人成无码久久电影网站| 999zyz**站免费毛片| 久久亚洲国产成人精品性色| 成人网站免费观看| 一级毛片a女人刺激视频免费| 永久免费观看的毛片的网站| 羞羞视频免费观看| 亚洲精品中文字幕乱码三区| 亚洲视频在线免费播放| 亚洲AV综合色一区二区三区| 免费无遮挡无码视频在线观看| 亚洲综合激情另类专区| 毛片无码免费无码播放| 亚洲阿v天堂在线| 亚洲美女视频免费| 国产成人亚洲综合a∨| 亚洲av最新在线网址| 好爽…又高潮了毛片免费看 | 99久久久国产精品免费蜜臀| 亚洲精品av无码喷奶水糖心|