亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標(biāo)題: Spring Struts整合方案匯總小結(jié) [打印本頁]

作者: sunday_jia    時間: 2010-01-14 11:09
標(biāo)題: Spring Struts整合方案匯總小結(jié)



Spring和Struts整合的方案有很多種,整理如下:
第一種 Listener方式
將Spring服務(wù)作為web容器的Listener,隨web服務(wù)器啟動而啟動
   1、需要在web.xml中配置
Java代碼

  •    
  • class>org.springframework.web.context.ContextLoaderListenerclass>   
  •   
    org.springframework.web.context.ContextLoaderListener
       2、然后在Struts的action中通過
    Java代碼

  • ServletContext sc = this.getServlet().getServletContext();   
  • WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sc);   
  • ctx.getBean("xxx");  ServletContext sc = this.getServlet().getServletContext();
    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sc);
    ctx.getBean("xxx");
    完成托管Bean的獲取。
    第二種 Load on Startup Servlet方式
    將Spring服務(wù)作為web容器的load on startup Servlet,隨web服務(wù)器啟動而啟動,這種方式和第一種基本是一樣的,只是spring加載的時間會比第一種晚一些,servlet2.3標(biāo)準(zhǔn),listener的加載早于startup servlet的加載
       1、這種方式需要在web.xml中配置
    Java代碼

  •    
  • contextLoader   
  • class>org.springframework.web.context.ContextLoaderServletclass>   
  • 1   
  •   
    contextLoader
    org.springframework.web.context.ContextLoaderServlet
    1
       2、這種整合方案,獲取bean的方法,和第一種方式相同
    第三種 Struts Plugin+Spring DelegatingRequestProcessor方式
    前兩種方式,都沒有將struts的action納入spring管理,接下來的要說的兩種方式比較類似,放在一起說明,都是可以將Struts的action納入到Spring管理的方式。
       1、通過Struts的Plugin方式,在應(yīng)用啟動時加載Spring容器,既然是Struts的Plugin,當(dāng)然是在struts-xxx.xml文件中進行配置,增加如下Plugin:
    Java代碼

  • "org.springframework.web.struts.ContextLoaderPlugIn">   
  • "contextConfigLocation" value="/WEB-INF/applicationContext.xml,/WEB-INF/applicationContext_xxx.xml"/>   
  •   
       2、Struts是通過ActionServlet處理請求的,而代碼實現(xiàn)上是通過RequestProcessor進行處理的,通過Spring的RequestProcessor子類-DelegatingRequestProcessor,可以替代原有的Struts請求處理方式,從而轉(zhuǎn)到Spring容器中進行處理。因此需要更改原有的Struts RequestProcessor行為,使用Spring自己的DelegatingRequestProcessor,這需要在struts-xxx.xml中配置,增加如下配置:
    Java代碼

  • "org.springframework.web.struts.DelegatingRequestProcessor">  
       3、經(jīng)過上面的配置,現(xiàn)在struts的action已經(jīng)交給spring來管理了,spring的DelegatingRequestProcessor會處理web請求,將請求轉(zhuǎn)發(fā)給struts-xxx.xml中定義的action,而這些action又是通過spring管理的,因此原來的struts配置文件中的action配置:...中的type就可以省略了,改成...,而type的設(shè)置則放到spring的配置文件中,上文中指定了兩個spring配置文件/WEB-INF/applicationContext.xml,/WEB-INF/applicationContext_xxx.xml,我們在其中一個文件中加入:
    Java代碼

  • "/login" class="com.soar.loginAction" singleton="false">   
  • "xx">   
  •    just a String property   
  •    
  •    
  •   

       just a String property


    這和對待普通的bean沒有什么區(qū)別了,但是名字是struts配置文件中指定的path指定的值"/login",設(shè)置singleton="false"是每請求一次,生成一個action(和struts1默認(rèn)策略不同)
    這樣就完成了spring與struts的整合以及spring管理action


    本文來自ChinaUnix博客,如果查看原文請點:http://blog.chinaunix.net/u2/69320/showart_2148617.html




    歡迎光臨 Chinaunix (http://72891.cn/) Powered by Discuz! X3.2
  • <bdo id="rsd7d"></bdo>
  • <bdo id="rsd7d"><strong id="rsd7d"></strong></bdo>

  • <tt id="rsd7d"></tt>