您的位置:首页 > 其它

使用 DelegatingActionProxy

2017-04-26 17:47 183 查看
本篇文章主要介绍了"使用 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="req
4000
uest"      

    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重载时,此种方式将异常繁琐。

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: