1.在action中取得beanfactory物件,然後通過beanfactory獲取業務邏輯物件
web.xml
2、將業務邏輯物件通過spring注入到action中,從而避免了在action類中的直接**查詢,web.xml配置同上
在struts-config.xml檔案中配置action 標籤中的type屬性需要修改為org.springframework.web.struts.delegatingactionproxy delegatingactionproxy是乙個action,主要作用是取得beanfactory,然後根據中的path屬性值 到ioc容器中取得本次請求對應的action
在spring配置檔案中需要定義struts的action,如:
這裡的name名稱要與標籤的path屬性值一致
將scope設定為prototype,這樣就避免了struts action的執行緒安全問題
必須注入業務邏輯物件
private noteservice noteservice ;
3、使用spring 的 actionsupport整合struts, struts-config.xml新增**如下:
action裡繼承 spring 的actionsupport
而不是 strutsaction
類擴充套件如下:
4、使用spring 的delegatingrequestprocessor
覆蓋struts 的requestprocessor
struts-config.xml檔案修改如下:
Spring,Struts整合方式
為了在struts中載入spring context,需要在struts config.xml檔案中加入如下部分 第一種方法 通過struts的plug in在struts和spring之間提供了良好的結合點。通過plug in我們實現了spring context的載入,不過僅僅載入spring ...
spring struts 無縫整合方式
step1 依賴和基本常識 1.首先要新增整合的核心jar包 struts2 spring plugin 2.3.16.3.jar。2.按照名稱匹配的原則,定義業務bean和action中的setter方法,注意呼叫的是set方法而不是屬性,但是一般命名一致便於閱讀。3.struts.xml中按照正...
spring struts整合 兩種方案
spring struts整合 第一種方案 原理 在action中取得beanfactory物件,然後通過beanfactory獲取業務邏輯物件 總結,從action上來看這種方案存在的缺點,它產生了依賴,loginaction如果離開spring,loginaction依賴了beanfactory...