每種整合技術(或者竅門)都有自己的 優點和特點。我偏愛其中的一種,但是我知道這三種都能夠加深您對 Struts 和 Spring 的理解。在處理各種不同情況的時候,這將給您提供 一個廣闊的選擇範圍。方法如下:
使用 Spring 的 ActionSupport 類整合 Structs
使用 Spring 的 DelegatingRequestProcessor 覆蓋 Struts 的 RequestProcessor
將 Struts Action 管理委託給 Spring 框架
裝載應用程序環境
無論您使用哪種技術,都需要使用 Spring 的 ContextLoaderPlugin 爲 Struts 的 ActionServlet 裝載 Spring 應用程序環境。就像添加任何其他插件一樣,簡單地向您的 struts-config.xml 文件添加該插件,如下所示:
"org.springframework.web.struts.ContextLoaderPlugIn">
"contextConfigLocation" value="/WEB-INF/beans.xml"/>
特別:struts-config中的plug-in 是:
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/WEB-INF/validator-rules.xml, /WEB-INF/validation.xml" />
</plug-in>
在web.xml添加listener:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>