How does the web container manage the lifecycle of a spring controller

前端 未结 1 829
别跟我提以往
别跟我提以往 2021-01-06 23:04

If i write a simple servlet application, in my servlet class i extend the http servlet. This lets the container know that my class is a servlet and it will manage the \'life

相关标签:
1条回答
  • 2021-01-06 23:56

    But will this spring controller class be 'mananged' by the container in a same way a servlet lifecyle is managed?

    Not directly. Then entry point of a Spring MVC application is typically a DispatcherServlet*. This class extends (not directly, but through inheritance) HttpServlet. You declare it as you would any other Servlet, typically in web.xml.

    However you don't declare it by itself. You provide a Spring ApplicationContext from which the DispatcherServlet can go and get the @Controller annotated classes it will use to handle requests.

    The DispatcherServlet handler stack is pretty big. There are many components involved. The official Spring MVC is an excellent document. You should read it.

    *I say typically because Spring provides other handlers, HttpRequestHandler for example.


    Additional Reading:

    1. Spring MVC and Servlets 3.0 - Do you still need web.xml?
    2. What happens behind the scenes of deploying a Spring MVC application to tomcat outside of eclipse?
    3. What's the difference between @Component, @Repository & @Service annotations in Spring?
    4. Spring MVC: difference between <context:component-scan> and <annotation-driven /> tags?
    5. Difference between <context:annotation-config> vs <context:component-scan>
    6. ContextLoadListener and DispatcherServlet
    0 讨论(0)
提交回复
热议问题