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

          Web應用初始化Spring容器策略

          以下軟件測試環境為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默認加載配置文件命名規則是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來初始化(應用服務器需要支持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 用于提供"后臺"服務,作為容器管理應用中的其他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 閱讀(2271) 評論(0)  編輯  收藏 所屬分類: OpenSource

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


          網站導航:
           
          主站蜘蛛池模板: 上饶市| 沈丘县| 开原市| 天门市| 淅川县| 宜良县| 新源县| 伊宁县| 皮山县| 绥阳县| 拉孜县| 开封县| 北安市| 朝阳区| 延川县| 鹤山市| 随州市| 五大连池市| 丰顺县| 松原市| 岳阳市| 金门县| 贡山| 巨野县| 读书| 湖南省| 日土县| 宜兰市| 阿尔山市| 秭归县| 综艺| 崇明县| 江西省| 普宁市| 德江县| 金坛市| 五台县| 博湖县| 涿州市| 南和县| 安塞县|