使用 DelegatingActionProxy

本篇文章主要介绍了"使用 DelegatingActionProxy",主要涉及到使用 DelegatingActionProxy方面的内容,对于使用 DelegatingActionProxy感兴趣的同学可以参考一下。

先使用一个问题简单讲一下:

Spring 中如何通过DelegatingActionProxy整合struts

需要先在 web.xml中 配置listener
然后在 struts-config.xml 中修改action中的type
为 org.springframework.web.struts.DelegatingActionProxy
还要加个 <plug-in>
然后在 Spring的配置文件中配置对应的bean


【最佳方案】使用
DelegatingActionProxy将Struts Action 管理全权委托给Spring 框架Action 的创建和对象的依赖注入全部由IOC容器来完成,使用Spring的DelegatingAcionProxy来帮实现代理的工作.DelegatingActiongProxy继承于org.apache.struts.action.Action 。此时需要将struts-   config.xml中所有Action类别全部配置为
 org.springframework.web.struts.DelegatingActionProxy:
 <action   
    attribute="loginForm"   
     input="/login.jsp"   
    name="loginForm"      
    path="/login"     
    scope="request"      
    type="org.springframework.web.struts.DelegatingActionProxy">       
    <forward name="error" path="/error.html" />    
    <forward name="success" path="/success.html" /> 
</action>



3,4两种方式都需要在WEB-INF下新建一个action-servlet.xml作为Spring context文件,创建Struts Action Bean,并对Action进行BO或DAO Bean注入:
<!--name 的取值一定要和Struts 配置文件action 中的path 的值相对应--> 
<bean name="/login" class="cn.qdqn.ssh.struts.action.LoginAction">      
<property name="userBO">    
 <ref bean="userBO"/>  
 </property> 
</bean>  


结论:
   
以上2种方式实现了由Spring管理Struts的Action,从而可以利用Spring在Struts Action中轻松的注入BO或DAO,还可以将 Spring 的 AOP 拦截器应用于Struts 动作,用最小的代价处理横切关注点。
   
第3种整合方式只需要配置一个<controller>,不需要改动Struts Action配置信息,但Struts的 RequestProcessor只能被重载一次,如果在应用中还要进行编码等其它功能RequestProcessor重载时,此种方式将异常繁琐。
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值