Spring集成Struts方法簡述
以下說明如何實現spring集成struts。
1、應用服務器沒有直接調用啟動Spring的方法,但是應用服務器編譯運行servlet,filter,listener,所以spring提供一個listener類,在服務器初始化的時候調用該類中的方法,所以在容器中配置如下:
- < !-- 指定spring的配置文件,多個文件之間用逗號分隔 -->
- < context-param>
- < param-name>contextConfigLocation< /param-name>
- < param-value>classpath:beans.xml< /param-value>
- < /context-param>
- < !-- 啟動Spring容器 -->
- < listener>
- < listener-class>org.springframework.web.context.ContextLoaderListener< /listener-class>
- < /listener>
2、我們把我們需要交給spring管理的類在beans.xml中配置:
如
- < bean name="/user/regist"
- class="cn.sun.ssh.web.action.UserManagerAction">
- < property name="dao" ref="userDAO">< /property>
- < /bean>
但是action是被引擎調用的,我們如何把需要的action交給引擎呢,通過重寫struts中的requestprocessor類中的processactioncreate方法,在spring中獲得action后交給引擎管理,這也是struts的一個擴展機制。
所以我們要在struts-config.xml中配置controller
- < controller>
- < set-property property="processorClass" value="org.springframework.web.struts.DelegatingRequestProcessor"/>
- < /controller>
這樣就實現了Spring集成Struts。
【編輯推薦】