您现在的位置是:首页 >

spring与struts的区别 Spring 和struts 整合的三种方式[3]

火烧 2022-03-03 22:35:43 1062
S ri g 和 trut 整合的三种方式[3]    全权委托 Actio 的创建和对象的依赖注入全部由IOC容器来完成 使用S ri g的Delegati gAcio Proxy来帮助实现代理的工

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]

  理由

   第一种使得过多的耦合了Spring和Action

   RequestProcessor类已经被代理 如果要再实现自己的实现方式(如 编码处理)怕有点麻烦

  总结一下

  整合工作中的步骤

   修改struts config xml

   配置applicationContext xml

   为Action添加get/set方法 来获得依赖注入的功能

lishixinzhi/Article/program/Java/ky/201311/29076  
永远跟党走
  • 如果你觉得本站很棒,可以通过扫码支付打赏哦!

    • 微信收款码
    • 支付宝收款码