歡迎使用我的 在線工具

          小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 閱讀(1122) 評論(0)  編輯  收藏 所屬分類: Java框架


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


          網站導航:
           
          主站蜘蛛池模板: 英德市| 凤翔县| 广平县| 海城市| 天台县| 乌恰县| 泗阳县| 洪雅县| 昭苏县| 城步| 北宁市| 乌拉特中旗| 久治县| 昌吉市| 卢龙县| 阿瓦提县| 玉屏| 镇康县| 林甸县| 阿图什市| 额尔古纳市| 普陀区| 屯留县| 定日县| 永泰县| 霍城县| 靖安县| 天气| 吉安县| 西贡区| 青州市| 天等县| 武邑县| 顺昌县| 文昌市| 华阴市| 泸水县| 林甸县| 闽侯县| 集安市| 石狮市|