歡迎使用我的 在線工具

          小D

          讀歷史、看小說、寫程序都是我所愛。技術不好,頭腦不靈光,靠的是興趣。
          隨筆 - 35, 文章 - 25, 評論 - 13, 引用 - 0
          數據加載中……

          Spring與Struts1.X的集成

          spring+struts的集成(第一種集成方案)
          原理:在Action中取得BeanFactory對象,然后通過BeanFactory獲取業務邏輯對象

          1、spring和struts依賴庫配置
          ?* 配置struts
          ??--拷貝struts類庫和jstl類庫
          ??--修改web.xml文件來配置ActionServlet
          ??--提供struts-config.xml文件
          ??--提供國際化資源文件
          ?* 配置spring
          ??--拷貝spring類庫
          ??--提供spring配置文件
          ??
          2、在struts的Action中調用如下代碼取得BeanFactory
          ?BeanFactory factory = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession().getServletContext());

          3、通過BeanFactory取得業務對象,調用業務邏輯方法???
          ??
          ?
          spring+struts的集成(第二種集成方案)
          原理:將業務邏輯對象通過spring注入到Action中,從而避免了在Action類中的直接代碼查詢

          1、spring和struts依賴庫配置
          ?* 配置struts
          ??--拷貝struts類庫和jstl類庫
          ??--修改web.xml文件來配置ActionServlet
          ??--提供struts-config.xml文件
          ??--提供國際化資源文件
          ?* 配置spring
          ??--拷貝spring類庫
          ??--提供spring配置文件
          2、因為Action需要調用業務邏輯方法,所以需要在Action中提供setter方法,讓spring將業務邏輯對象注入過來

          3、在struts-config.xml文件中配置Action
          ??* <action>標簽中的type屬性需要修改為org.springframework.web.struts.DelegatingActionProxy
          ?? DelegatingActionProxy是一個Action,主要作用是取得BeanFactory,然后根據<action>中的path屬性值
          ?? 到IoC容器中取得本次請求對應的Action
          ??
          4、在spring配置文件中需要定義struts的Action,如:
          ?<bean name="/login" class="com.bjsxt.usermgr.actions.LoginAction" scope="prototype">
          ??<property name="userManager" ref="userManager"/>
          ?</bean>
          ?* 必須使用name屬性,name屬性值必須和struts-config.xml文件中<action>標簽的path屬性值一致
          ?* 必須注入業務邏輯對象
          ?* 建議將scope設置為prototype,這樣就避免了struts Action的線程安全問題
          ? ? ??
          ??
          ? ??

          posted on 2009-11-04 21:12 vagasnail 閱讀(1125) 評論(0)  編輯  收藏 所屬分類: Java框架


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


          網站導航:
           
          主站蜘蛛池模板: 乐亭县| 黄大仙区| 色达县| 吉首市| 莱州市| 惠水县| 松滋市| 遵化市| 齐齐哈尔市| 嘉善县| 佛冈县| 老河口市| 柯坪县| 通河县| 海门市| 蓬莱市| 临沭县| 博兴县| 宿州市| 云和县| 高雄县| 包头市| 榆中县| 安徽省| 库尔勒市| 宣恩县| 洞头县| 海晏县| 西林县| 尚志市| 普洱| 宁陵县| 北流市| 恭城| 东乡县| 清水县| 濮阳市| 河南省| 永顺县| 海阳市| 正阳县|