隨筆-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

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


          網站導航:
           
          主站蜘蛛池模板: 门源| 湖口县| 铜梁县| 荆门市| 务川| 龙海市| 镇巴县| 丹寨县| 都安| 永平县| 南雄市| 龙海市| 锡林郭勒盟| 呼玛县| 庆安县| 平罗县| 海城市| 九台市| 博罗县| 左权县| 枝江市| 慈利县| 时尚| 揭东县| 弥渡县| 湘西| 舟山市| 贵港市| 清水县| 额济纳旗| 汶川县| 丘北县| 房产| 乾安县| 淮南市| 九台市| 会宁县| 绥德县| 浏阳市| 铜鼓县| 岳西县|