zoukankan      html  css  js  c++  java
  • Spring IoC容器管理Action

    Spring IoC容器管理Action有两种方式:DelegatingRequestProcessor、DelegatingActionProxy

    不管采用哪一种方式,都需要随应用启动时创建ApplicationContext实例,由Struts负责在应用启动时创建ApplicationContext实例。Struts中提供了PlugIn的扩展点,可在应用启动和关闭时,创建或销毁某些资源。

    使用ContextLoaderPluIn创建了ApplicationContext实例后,关键是如何将AtionServlet拦截的请求,转发给Spring管理的bean。

    ActionServlet将请求转发到Spring容器,有以下两个时机:在ActionServlet之处将处理转发给Spring容器中的bean、在Action之处将处理转发给Spring容器中的bean。

    根据这两个时机,完成这个转发也有以下两种策略:采用DelegatingRequestProcessor,在ActionServlet出完成转发、采用DelegatingActionProxy,在Action出完成转发。

    查看 Struts 的源代码,我们可以看到由 ActionServlet 调用 RequestProcessor 完成实 际的转发。如想在 ActionServlet 处将请求转发给 ApplicationContext 的 bean ,可以通过 扩展 RequestProcessor 完成,使用扩展的 RequestProcessor 替换 Struts 的 RequestProcessor ,例如:

    //使用 spring 的 RequestProcessor 替换 struts 原有的 RequestProcessor

    <controller processorClass="org.springframework.web.struts.Delegating RequestProcessor"/>      

    DelegatingRequestProcessor 可直接替换了原有的 RequestProcessor,并在请求转发给 action 之前,转发给 Spring 管理的 bean; 而 DelegatingActionProxy 则被配置成 Struts 的 action,即所有的请求先被 ActionServlet 拦截,然后将请求转发到对应的 action,而 action 的实现类全都是 DelegatingActionProxy; 最后由 DelegatingActionProxy 将请求转发给 Spring 容器的 bean。

  • 相关阅读:
    [转]myeclipse 生成JAR包并引入第三方包
    Composer 基本指令操作使用
    Laravel Eloquent ORM
    [转]Spring Boot——2分钟构建spring web mvc REST风格HelloWorld
    C# IoC 容器
    【转载】laravel的MVC
    [转]Laravel 4之Eloquent ORM
    [转]Laravel 4之数据库操作
    svn unable to connect to a repository at url 执行上下文错误 不能访问SVN服务器问题
    Make a travel blog by Blogabond the theme of wordpress
  • 原文地址:https://www.cnblogs.com/yzp666/p/7593616.html
Copyright © 2011-2022 走看看