網上有好多種struts+spring的集成思路,例如 http://dev.csdn.net/author/hql638/35679289a9a94e4f97e999508df064db.html 這篇文章就介紹得很詳細,介紹了下面三種方法:
使用 Spring 的 ActionSupport 類整合 Structs 使用 Spring 的 DelegatingRequestProcessor 覆蓋 Struts 的 RequestProcessor 將 Struts Action 管理委托給 Spring 框架 其實在使用spring+struts時,我們往往就是想使用Ioc的特性,減少業務邏輯組件之間的依賴關系,通過高度靈活的XML配置提高業務的靈活性和擴展性。步驟如下:首先依舊加入spring的context plugin到struts-config.xml中
然后包裝一下struts的DispatchAction,提供一個方法可以直接獲取Spring的WebApplicationContext對象。
然后自己的action可以直接從CommDispatchAction繼承通過this.getAppContext();獲取WebApplicationContext,這樣對原有的struts程序架構體系幾乎沒有太大的變化,同時可以引入spring的Ioc特性到現有系統中,這個與ActionSupport 中的getWebApplicationContext()方法類似了,但是可以不必拘泥于在兩者之間轉來轉去的。
Powered by: BlogJava Copyright © 在路上...