<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)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    收藏夾

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 久久午夜免费视频| 久久免费视频99| 精品久久免费视频| 亚洲人成色777777老人头| 啦啦啦中文在线观看电视剧免费版| 亚洲欧洲国产精品久久| 99久久99这里只有免费费精品| 久久久久亚洲AV无码观看| 最近2019中文字幕免费大全5| 亚洲日韩乱码中文无码蜜桃| 噼里啪啦免费观看高清动漫4 | 日韩高清在线免费观看| 亚洲日韩中文字幕一区| 又爽又高潮的BB视频免费看| CAOPORM国产精品视频免费| 国产亚洲精品美女久久久| 久久青草免费91观看| 亚洲乱码一区二区三区国产精品| 成人毛片免费观看视频在线| 色吊丝免费观看网站| 亚洲欧洲日产国码无码网站 | 思思99re66在线精品免费观看| 亚洲男同gay片| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 在线毛片片免费观看| 亚洲精品第五页中文字幕| 成人免费福利电影| fc2成年免费共享视频18| 亚洲Aⅴ无码专区在线观看q| 美女网站免费福利视频| 免费人成大片在线观看播放| 亚洲AV综合色区无码另类小说| 成人免费黄色网址| 羞羞视频在线观看免费| 内射干少妇亚洲69XXX| 精品少妇人妻AV免费久久洗澡| 51午夜精品免费视频| 亚洲成人网在线观看| 免费大黄网站在线观看| 最近中文字幕国语免费完整| 日日摸日日碰夜夜爽亚洲|