歡迎使用我的 在線工具

          小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框架


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


          網站導航:
           
          主站蜘蛛池模板: 芦溪县| 内丘县| 登封市| 开江县| 蓬安县| 东明县| 湖州市| 井研县| 文昌市| 洛阳市| 汕头市| 阿拉尔市| 墨脱县| 铜川市| 凉城县| 洛阳市| 随州市| 乐至县| 彭山县| 呼伦贝尔市| 淮南市| 子洲县| 吉林省| 承德市| 丰台区| 平罗县| 平谷区| 子洲县| 浦县| 弋阳县| 抚宁县| 南木林县| 昭觉县| 清流县| 黄大仙区| 鹤峰县| 曲麻莱县| 双牌县| 双城市| 衡山县| 泸水县|