Spring中MVC的问题?

来源:百度知道 编辑:UC知道 时间:2024/06/18 06:23:22
怎样用Spring 来实现struts中DispatchAction的功能?
加入spring还得在struts配置<action...></action>
哪用spring还有什么好处呢?

用Spring来代理Struts,简单来说,在struts-config.xml中,写成
<action ..(省略了一些参数)
type="org.springframework.web.struts.DelegatingActionProxy">注意里面的type属性,把控制权转给spring,然后还要在后面加入spring的插件
<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml,applicationContext_ext.xml(spring来代理struts的xml)"/>
</plug-in>

这个xml里面的bean可以写成这样
<bean name="..(这里就可以写本来struts配置文件里的action路径了,比如 /index 等等)"
class="..">
<property ..></property>
</bean>

补充回答:
Struts Action类和Spring是低耦合的,它仅仅依赖了Spring提供的反转控制(IoC)机制注入到了我们的Action中,另外,使用DelegatingActionProxy的好处在于我们可以不使用任何Spring特定的类来编写Struts Action.同时,Struts动作能够利用IoC取得和他合作的对象.总之,慢慢深入spring和struts集成的框架就会理解了,我也在学习中!

用 plugIn,
1. 假设struts中有一个action: UserAction
<action name="U