今天練習了dwr與struts和spring集成,其中與struts集成有點小錯誤還沒查出來,在網上找資料也沒有解決。Spring集成倒是挺爽的,順便回顧了spring的設置,如果spring和strtus集成,首先無論哪種方式都需要在struts-config.xml中以插件方式引入spring的一個加載類ContextLoaderPlugin
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" />
</plug-in>
可以用spring的一個接口DelegatingRequestProcessor替換org.apache.struts.action.RequestProcessor類,在web.xml中設置.
還可以將struts的Action類交給spring的代理類來處理。
還有就是如果只是簡單web應用,不用struts,那么在web.xml配置文件中配置一個spring監聽器或者servlet,例如
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
這樣在用到spring Ioc中的對象時就用WebApplicationContextUtils來加載。