zoukankan      html  css  js  c++  java
  • Spring MVC中的Controller是Serlvet吗?

    1. Controller不是Servlet

    DispatcherServler是Spring MVC中的唯一Servlet,(这点可通过查看FrameworkServlet的子类确认)
    Servlet容器(Tomcat)把所有请求都转发到DispatcherServler
    然后通过HandlerMapping把请求路由到具体的Controller中。
    因此,Controller只是一个普通的JavaBean
    官网文档对@Controller注解的解释

    The @Controller annotation indicates that a particular class serves the role of a controller. Spring does not require you to extend any controller base class or reference the Servlet API. 
    However, you can still reference Servlet-specific features if you need to.
    

    2. DispatcherServlet由谁创建

    DispatcherServler的生命周期与普通的Servlet一样都是由Servlet容器管理,在第一次访问时创建,在容器关闭时销毁。
    显而易见的,DispatcherServler 实例在Servlet容器中,而不是Spring自己的IoC容器中。

  • 相关阅读:
    计算最大公因数
    最大子序列和问题
    C++三大函数:析构函数、复制构造函数和operator=
    C++函数返回值传递
    C++动态内存分配
    Halcon Assistants
    网格细分算法
    HDevelop Guide
    MeshLab
    point cloud registration
  • 原文地址:https://www.cnblogs.com/upnote/p/10449557.html
Copyright © 2011-2022 走看看