spring与struts的区别 Spring 和struts 整合的三种方式[3]
Spring 和struts 整合的三种方式[3]
全权委托
Action 的创建和对象的依赖注入全部由IOC容器来完成 使用Spring的DelegatingAcionProxy来帮助实现代理的工作 springframework web struts DelegatingActiongProxy继承于 apache struts action Action
全权委托的配置方式同 方式 类似 (applcationContext xml文件的配置和 Action类的实现方式相同)
<struts config> <data sources /> <form beans > <form bean name= loginForm type= cao struts form LoginForm /> </form beans>
<global exceptions /> <global forwards /> <action mappings > <! type指向的是spring 的代理类 > <action attribute= loginForm input= login jsp name= loginForm path= /login scope= request
type= springframework web struts DelegatingActionProxy > <forward name= success path= /ok jsp /> <forward name= error path= /error jsp /> </action> </action mappings> <message resources parameter= cao struts ApplicationResources />
<plug in className= springframework web struts ContextLoaderPlugIn > <set property property= contextConfigLocation value= /WEB INF/applicationContext xml /> </plug in>
</struts config>
不同之处
<action>中 type指向的是spring 的代理类
去掉struts config xml中 <controller >
三种整和方式中我们优先选用 全权委托的方式
![spring与struts的区别 Spring 和struts 整合的三种方式[3]](http://img.zhputi.com/uploads/bf7f/bf7faf75823b41fa51a2a71ac85b510328946.jpg)
理由
第一种使得过多的耦合了Spring和Action
RequestProcessor类已经被代理 如果要再实现自己的实现方式(如 编码处理)怕有点麻烦
总结一下
整合工作中的步骤
修改struts config xml
配置applicationContext xml
为Action添加get/set方法 来获得依赖注入的功能
lishixinzhi/Article/program/Java/ky/201311/29076