隨筆-16  評論-84  文章-1  trackbacks-0

          Web應用初始化Spring容器策略

          以下軟件測試環(huán)境為Spring,Struts1

          1、通過struts1提供的插件機制,采用Spring提供的ContextLoaderPlugIn

          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">

          <struts-config>
           <global-exceptions />
           <global-forwards />
           <message-resources parameter="com.portal.ApplicationResources" />
           <!--  通過S1提供的插件機制來初始化Spring容器,加載Spring配置文件
           <plug-in
            className="org.springframework.web.struts.ContextLoaderPlugIn">
            <!--
             1、ContextLoaderPlugIn默認加載配置文件命名規(guī)則是actionServlet-servlet.xml,其中actionServlet
             是配置org.apache.struts.action.ActionServlet時指定的servlet名稱
             
             2、通過配置contextConfigLocation屬性來指點Spring配置文件的位置,多個配置文件可以使用 逗號","、分號";"、空格" "
            -->
            <set-property property="contextConfigLocation"
             value="/WEB-INF/conf/spring-application.xml,/WEB-INF/conf/**/spring*.xml" />
           </plug-in> 
            -->
          </struts-config>


          2、采用Spring提供的ContextLoaderListener來初始化(應用服務(wù)器需要支持Listener,Servlet2.3版本及以上)
           <context-param>
             <description>通過配置contextConfigLocation屬性來指點Spring配置文件的位置,多個配置文件可以使用 逗號","、分號";"、空格" "</description>
             <param-name>contextConfigLocation</param-name>
             <param-value>/WEB-INF/conf/spring-application.xml /WEB-INF/conf/**/spring*.xml</param-value>
            </context-param>
           
            <listener>
             <description>通過ContextLocaderListener來初始化Spring容器,加載Spring配置文件</description>
             <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
            </listener>

          3、采用load-on-startup Servlet 來初始化Spring容器
            <servlet>
             <description>
              通過load-on-startup Servlet來初始化Spring容器
              該如何Servlet 用于提供"后臺"服務(wù),作為容器管理應用中的其他bean,不需要響應客戶請求,因此無須配置servlet-mapping
             </description>
             <servlet-name>applicationContext</servlet-name>
             <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
             <load-on-startup>0</load-on-startup>
            </servlet>

          posted on 2010-09-13 18:10 absolute 閱讀(2277) 評論(0)  編輯  收藏 所屬分類: OpenSource

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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 繁峙县| 镇安县| 浑源县| 伊春市| 合川市| 滨州市| 长葛市| 吴堡县| 榆中县| 大洼县| 盘锦市| 孙吴县| 彰武县| 五寨县| 威信县| 双流县| 安达市| 乳源| 庄浪县| 拉萨市| 十堰市| 涡阳县| 杂多县| 阳东县| 左权县| 林周县| 四子王旗| 黄平县| 广西| 松江区| 宁阳县| 苍梧县| 林芝县| 谢通门县| 台北市| 富锦市| 稷山县| 本溪| 安康市| 剑阁县| 长垣县|