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容器中。

  • 相关阅读:
    《结对-贪吃蛇游戏-最终程序》
    《团队-科学计算器-模块测试过程》
    Bootstrap
    Angularjs的核心概念
    jQuery Ajax
    浏览器为什么会有兼容性问题
    BFC
    sass
    HTML5
    面向过程和面向对象编程
  • 原文地址:https://www.cnblogs.com/upnote/p/10449557.html
Copyright © 2011-2022 走看看